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 |
|
satheesh
Posting Yak Master
152 Posts |
Posted - 2011-03-31 : 11:24:05
|
| Hi all,I need to find the total sales by each month for last 3 year for eg:select COUNT(cst.cstid) from customer where (cst.StartDate between '2010-01-01 00:00:00.000' AND '2010-12-31 23:59:59.997')this will give one year total sales.But I need to find month wise.Is there any easy way to do this.Any help will be highly appreciated.Regards,SGexpected result:Month totalsalesJan 245feb 55----Dec 12 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-03-31 : 11:32:57
|
[code]select dateadd(month, datediff(month, 0, cst.StartDate), 0), COUNT(cst.cstid) from customerwhere (cst.StartDate between '2010-01-01 00:00:00.000' AND '2010-12-31 23:59:59.997')GROUP BY dateadd(month, datediff(month, 0, cst.StartDate), 0)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
satheesh
Posting Yak Master
152 Posts |
Posted - 2011-03-31 : 12:24:29
|
| Thanks Khtan.Its working. |
 |
|
|
|
|
|