SYSK 252: Running SQL statements at a desired time

Say, you need to run a certain stored proc or some T-SQL commands, but you must do it “after normal hours”… You could sit and wait until the time you are allowed to hit that F5 (run) key in Query Analyzer, or you could create and schedule a SQL Agent job… But if it’s a onetime thing, you could also use the WAITFOR TIME statement like follows:

WAITFOR TIME '19:00:00'

BEGIN

-- Your code goes here

END

You could even send yourself an e-mail with the results (success or failure), so you don’t have to VPN from home and check on the progress from time to time…