SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sum by Date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

satheesh
Posting Yak Master

United Kingdom
146 Posts

Posted - 08/12/2013 :  11:25:05  Show Profile  Reply with Quote
Hi All,

I need to sum up total policy from 2012 Jan to Today 11.Aug.2013

Just need to sum up the same duration each month ie. First 11 days

select 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 appreciated

Thaaks

Regards,
SG

MuMu88
Aged Yak Warrior

547 Posts

Posted - 08/12/2013 :  11:43:07  Show Profile  Reply with Quote
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.2013

Just need to sum up the same duration each month ie. First 11 days

select 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 appreciated

Thaaks

Regards,
SG

Go to Top of Page

satheesh
Posting Yak Master

United Kingdom
146 Posts

Posted - 08/12/2013 :  12:34:54  Show Profile  Reply with Quote
Thanks MuMu.Its Working.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000