Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Question about date and reports
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

15 Posts

Posted - 12/03/2012 :  13:09:28  Show Profile  Reply with Quote
Hello , here is my question, i would like to run a job that creates a report every month. This report will be run on the 15th of every month. What i need is the report to show from the previous month of the 15th to the current month 14th. I know I have to use a datediff and probably a dateadd but not to sure how to go about it. Any help would be appreciated thanks.

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/03/2012 :  14:24:40  Show Profile  Reply with Quote
Use a where clause like this:
	YourDateColumn >= DATEADD(mm,DATEDIFF(mm,0,GETDATE())-1,14)
	AND YourDateColumn < DATEADD(mm,DATEDIFF(mm,0,GETDATE()),14)
This is really asking to start on the 15th of last month and go up to anything that is LESS than the 15th of the current month - which is the best way to do what you described.

Edited by - sunitabeck on 12/03/2012 14:26:31
Go to Top of Page

Starting Member

15 Posts

Posted - 12/03/2012 :  14:33:14  Show Profile  Reply with Quote
Thanks sunitabeck for Responding, I'll give that a try.
Go to Top of Page

Starting Member

15 Posts

Posted - 12/03/2012 :  15:50:06  Show Profile  Reply with Quote
Thanks again sunitabeck it worked just like I needed it too
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 12/04/2012 :  01:09:02  Show Profile  Reply with Quote
see this to understand the logic used

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next 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