http://www.sqlservercurry.com/2010/10/execute-t-sql-code-only-on-certain-days.html
I always clean up my databases manually on Sundays. But at times, if need be, I clean it up on other days as well. However I never do it on Saturdays, since the traffic is usually the most on that day.
So here’s a simple tip using IF-ELSE to prevent my T-SQL code from running on Saturday’s, even if I run the code manually
IF DATEPART(dw,GETDATE())<> 7 -- 7 is Saturday, 1 is SundayBEGIN -- YOUR T-SQL Code Comes Here SELECT GETDATE() RETURN END ELSE BEGIN PRINT '*** Sorry This Code will Not Execute on Saturdays'END
OUTPUT
You may also want to read Make a T-SQL Query Sleep for a certain amount of time
Ingen kommentarer:
Send en kommentar