Jaa


Control-of-Flow

Transact-SQL provides special words called control-of-flow language that control the flow of execution of Transact-SQL statements, statement blocks, user-defined functions, and stored procedures.

Without control-of-flow language, separate Transact-SQL statements are performed sequentially, as they occur. Control-of-flow language permits statements to be connected, related to each other, and made interdependent using programming-like constructs.

These control-of-flow words are useful when you need to direct Transact-SQL to take some kind of action. For example, use a BEGIN...END pair of statements when including more than one Transact-SQL statement in a logical block. Use an IF...ELSE pair of statements when a certain statement or block of statements needs to be executed IF some condition is met, and another statement or block of statements should be executed if that condition is not met (the ELSE condition).

The control-of-flow statements cannot span multiple batches, user-defined functions, or stored procedures.

These are the control-of-flow keywords.

BEGIN...END

BREAK

GOTO

CONTINUE

IF...ELSE

WHILE

RETURN

WAITFOR

See Also

Concepts

Using GOTO
Using WAITFOR
Using RETURN

Other Resources

CONTINUE (Transact-SQL)
DECLARE @local\_variable (Transact-SQL)
ELSE (IF...ELSE) (Transact-SQL)
END (BEGIN...END) (Transact-SQL)
Control-of-Flow Language (Transact-SQL)
EXECUTE (Transact-SQL)
-- (Comment) (Transact-SQL)
IF...ELSE (Transact-SQL)
/*...*/ (Comment) (Transact-SQL)
PRINT (Transact-SQL)
BEGIN...END (Transact-SQL)
RAISERROR (Transact-SQL)
BREAK (Transact-SQL)
WHILE (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance