hello all
i have table1 with 2 columns
column1 for datetime
column2 for integer value
Date value
2/2/2010 100
2/4/2010 200
3/5/2010 90
3/6/2010 110
how is the statement to sum the value in pebruary,in march etc.
tq
denny
Loading
Kirtan PatelPosted Mar 1, 2010, 4:25 AM
select month(Date) as "Month",sum([Values]) as "Sum" from Table1 group by month(Date);
here is Output
if my answer helps you then check "Do you like this answer" check box :)
kiran kumarPosted Mar 1, 2010, 12:50 AM
try this statement
//this is for febrauray month
SELECT sum(value) FROM table1 WHERE DATEPART(m,Date) = 2 AND DATEPART(yyyy,Date) = 2010;
//this is for march month
SELECT sum(value) FROM table1 WHERE DATEPART(m,Date) = 3 AND DATEPART(yyyy,Date) = 2010;
//to sum up the records of the both the months i have written a stored procedure like this
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[total]
as
declare @sum int;
declare @sum1 int;
declare @sum2 int;
select @sum1= sum(value) from table1 where datepart(m,date)=2 and datepart(yyyy,date)=2010;
select @sum2= sum(value) from table1 where datepart(m,date)=3 and datepart(yyyy,date)=2010;
set @sum=@sum1+@sum2;
print @sum
mark the answer if it helps you