Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-02-20 : 05:56:20
|
Hi,how can i group data using specified date like for example per month.here is my sample data.fielddate | fieldnumberjanuary 1, 2007 | 1january 5, 2007 | 2February 2, 2007| 3March 4, 2007 | 3March 5, 2007 | 4i want to sum all fieldnumber by monthresult will be:resultdate | resultnumberjanuary 2007 | 3February 2007 | 3March 2007 | 7 thnx for the help in advance. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-20 : 06:00:58
|
group by CAST(MONTH(datefield) AS varchar(2))+CAST(year(datefield) AS varchar(4)) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-20 : 08:31:20
|
If the datatype of the column is DATETIME, thenSelect dateadd(month,datediff(month,0,fielddate ),0) as months,sum(fieldnumber) as fieldnumber from your_tableGroup by dateadd(month,datediff(month,0,fielddate ),0)MadhivananFailing to plan is Planning to fail |
|
|
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-02-20 : 19:34:30
|
nice.. thanks to both of u |
|
|
|
|
|
|
|