waitfor

Description

Specifies a specific time, a time interval, or an event for the execution of a statement block, stored procedure, or transaction.

Syntax

waitfor {delay time | time time | errorexit | processexit | mirrorexit} 

Parameters

delay

instructs Adaptive Server to wait until the specified amount of time has passed, up to a maximum of 24 hours.

time

instructs Adaptive Server to wait until the specified time.

time

a time in one of the acceptable formats for date/time data, or a variable of character type. You cannot specify dates—the date portion of the date/time value is not allowed. You can use the datatype time for this information.

errorexit

instructs Adaptive Server to wait until a kernel or user process terminates abnormally.

processexit

instructs Adaptive Server to wait until a kernel or user process terminates for any reason.

mirrorexit

instructs Adaptive Server to wait for a mirror failure.

Examples

Example 1

At 2:20 p.m., the chess table is updated with my next move, and a procedure called sendmail inserts a row in a table owned by Judy, notifying her that a new move now exists in the chess table:

begin 
    waitfor time "14:20" 
    insert chess (next_move) 
        values ('Q-KR5') 
    execute sendmail 'judy' 
end

Example 2

After 10 seconds, Adaptive Server prints the message specified:

declare @var char (8)
select @var = "00:00:10"
begin 
    waitfor delay @var 
    print "Ten seconds have passed.  Your time 
        is up." 
end

Example 3

After any process exits abnormally, Adaptive Server prints the message specified:

begin
    waitfor errorexit
    print "Process exited abnormally!"
end

Usage

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

waitfor permission defaults to all users. No permission is required to use it.

See also

Commands begin...end

Datatypes Date and time datatypes

System procedures sp_who