Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-12-03 : 14:24:40
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.
mclovin
Starting Member
15 Posts
Posted - 2012-12-03 : 14:33:14
Thanks sunitabeck for Responding, I'll give that a try.
mclovin
Starting Member
15 Posts
Posted - 2012-12-03 : 15:50:06
Thanks again sunitabeck it worked just like I needed it too