Export (0) Print
Expand All
6 out of 6 rated this helpful - Rate this topic

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.