DECLARE @Total INT = 0 ;
WHILE @Number < = 10
BEGIN
IF @NUMBER = 5
GOTO quantrimang;
ELSE
SET @Total = @Total + @Number;
SET @Number = @Number + 1 ;
END;
quantrimang
PRINT @Total;
GO
In the example using this GOTO statement, we created a label named quantrimang, when the @NUMBER variable reached value 5, the program allowed to jump to the position of the quantrimang label in the function and execute the statement following it. .
See more:
Previous lesson: CONTINUE command in SQL Server