Show TOC

GOTO Statement [T-SQL]Locate this document in the navigation structure

Branches to a labeled statement.

Syntax
<label> : GOTO <label>
Examples

(back to top)

  • Example 1 this Transact-SQL batch prints the message “yes” on the server window four times:
    declare @count smallint 
    select @count = 1 
    restart: 
    	print 'yes'
    	select @count = @count + 1 
    	while @count <=4 
    	 goto restart
Usage

(back to top)

Any statement in a Transact-SQL procedure or batch can be labeled. The label name is a valid identifier followed by a colon. In the GOTO statement, the colon is not used.

Standards

(back to top)

  • SQL—ISO/ANSI SQL compliant.
  • SAP Database products—SAP ASE supports the GOTO statement.
Permissions