Freigeben über


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…

Comments

  • Anonymous
    December 05, 2006
    Erk! There's a scheduler built into SQL server? Isn't that a bit redundant? Is there a way to run the proc/script from the system scheduler/"at" instead?

  • Anonymous
    December 24, 2006
    The comment has been removed

  • Anonymous
    December 24, 2006
    The comment has been removed