Saturday, January 3, 2009

SQL Server: WAITFOR TIME Statement

WAITFOR TIME SQL statement is used to set the particular time to execute the next query/SQL statement.

For Example the second query will execute when the particular time will be reached:

DECLARE @MyDateTime DATETIME
/* Add 5 seconds to current time so
system waits for 15 seconds*/
SET @MyDateTime = DATEADD(s,15,GETDATE())
SELECT GETDATE() CurrentTime
WAITFOR TIME @MyDateTime
SELECT GETDATE() CurrentTime

No comments: