GOTO label

Alters the flow of execution to a label. The SQL statement(s) following GOTO are skipped and processing continues at the label. GOTO statements and labels can be used anywhere within a procedure, batch, or statement block, and they can be nested.

Syntax

    Define the label:

    label:

    Alter the execution:

    GOTO label

where

label
Defines the point after which processing will begin if a GOTO is targeted to that label. Labels must follow the rules for identifiers. A label can be used as a commenting method regardless of whether or not GOTO is used.

Remarks

GOTO can exist within conditional control-of-flow statements, statement blocks, or procedures, but it cannot go to a label outside of the batch. GOTO branching can go to a label defined before or after GOTO.