SQL Server: WAITFOR Statement


The WAITFOR statement is used to delay execution of the T-SQL command for a specified period of time. This can be used to block the execution of a batch statement, a stored procedure or a T SQL command for a specified time. 

There are two parameters that can be used with the WAITFOR statement. 

waitforsqlserver1.gif
 
Let us create a simple stored procedure. 

waitforsqlserver2.gif 

Let us execute the preceding stored procedure after a delay of 1 minute. 

waitforsqlserver3.gif
 
In the preceding query we are using a delay with WAITFOR.
 
waitforsqlserver4.gif 

The preceding query will execute the stored procedure at 10.06PM. The time must be expressed using a 24 hours value.  For 1 PM we need to give input as 13:00. 

Up Next
    Ebook Download
    View all
    Learn
    View all