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.
I have a field in one of my tables called renew_date. The renew_date is always the first of every month. My requirement is to have a query that's run on the first of every month to select records that have renew_date coming up in the next 150 days.(5 months from today).ANY help is really appreciated.
In case the report isn't run until, say, the second of the month, or a renew_date is some date within a month, rather than the 1st of the moth, I would use:
WHERE renew_date >= DATEADD(Month, DATEDIFF(Month, 0, CURRENT_TIMESTAMP), 0) AND renew_data < DATEADD(Month, DATEDIFF(Month, 0, CURRENT_TIMESTAMP)+5, 0)
Kristen
kalyformin
Starting Member
15 Posts
Posted - 2007-10-14 : 17:10:47
Thank you both. It worked like a charm!
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2007-10-15 : 03:09:08
For more info on how to handle dates refer www.sql-server-performance.com/fk_datetime.aspMadhivananFailing to plan is Planning to fail