ARTICLE

SQL Server: WAITFOR Statement

Posted by Dhananjay Kumar Articles | SQL Server 2012 March 07, 2011
WAITFOR statement used to delay execution of T-SQL command for a specified period of time. This can be used to block the execution of batch statement, stored procedure and T SQL commands for a specified time.
Reader Level:

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. 

Login to add your contents and source code to this article
comments
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Nevron Diagram
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.