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
 Question about date and reports
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mclovin
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.

sunitabeck
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:
WHERE 
	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

mclovin
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

mclovin
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

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

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

http://visakhm.blogspot.in/2012/07/generate-datetime-values-from-integers.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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