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 - 2013-08-12 : 11:25:05
|
Hi All,I need to sum up total policy from 2012 Jan to Today 11.Aug.2013Just need to sum up the same duration each month ie. First 11 daysselect dateadd(month, datediff(month, 0, Policy .DateCreated ), 0), COUNT(Policy .PolicyId) from Policy Where (policy.datecreated between '2012-01-01 00:00:00.000' AND '2013-08-11 23:59:59.997') GROUP BY dateadd(month, datediff(month, 0, Policy .DateCreated), 0)The above query sum up all policy created on whole month up to August and group by month. But I just need first 11 days only for each month.How to amend the query.Any help will be highly appreciatedThaaksRegards,SG |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-12 : 11:43:07
|
Modify your query like this:quote: Originally posted by satheesh Hi All,I need to sum up total policy from 2012 Jan to Today 11.Aug.2013Just need to sum up the same duration each month ie. First 11 daysselect dateadd(month, datediff(month, 0, Policy .DateCreated ), 0), COUNT(Policy .PolicyId) from Policy Where (policy.datecreated between '2012-01-01 00:00:00.000' AND '2013-08-11 23:59:59.997') AND (DATEPART(dd, policy.datecreated) between 1 and 11)GROUP BY dateadd(month, datediff(month, 0, Policy .DateCreated), 0)The above query sum up all policy created on whole month up to August and group by month. But I just need first 11 days only for each month.How to amend the query.Any help will be highly appreciatedThaaksRegards,SG
|
|
|
satheesh
Posting Yak Master
152 Posts |
Posted - 2013-08-12 : 12:34:54
|
Thanks MuMu.Its Working. |
|
|
|
|
|
|
|