O'Reilly logo

Programming Microsoft® SQL Server™ 2008 by Leonard Lobel, Andrew Brust, and Stephen Forte

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The WAITFOR Statement

In SQL Server 2000, WAITFOR waited for a specified duration or a supplied datetime value. Starting with SQL Server 2005, as with the TOP enhancements, you can use WAITFOR with a SQL expression. You can essentially use the WAITFOR function to wait for a T-SQL statement to affect at least one row. (You can also set a time-out on that SQL expression.) You can specify WAITFOR to wait not only in SELECT statements but also in INSERT, UPDATE, DELETE, and RECEIVE statements. In essence, SELECT statements won’t complete until at least one row is produced, and data manipulation language (DML) statements won’t complete until at least one row is affected.

Here is the syntax:

WAITFOR(<statement>) [,TIMEOUT <timeout_value>]

This feature ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required