GOTO (TSQL Statement)
executes an unconditional jump to a point in script specified by the label.
Syntax
GOTO <label>
<label>:
Arguments
- <label>
- is a label name (it is an identifier).
Remarks
A label is an identifier followed by a colon :
, which gives a name to the specific point in script where it is defined.
Example
DECLARE @i INT = 0;
loop_start:
PRINT @i;
IF @i >= 3
GOTO loop_end;
SET @i += 1;
GOTO loop_start;
loop_end:
PRINT 'End';
The result is:
0
1
2
3
End