The topic describes the DF186 T-SQL code analysis rule.
BEST PRACTICE
GOTO statement is used.
To improve readability, it is recommended to avoid using the GOTO statement.
DECLARE @Counter int;
SET @Counter = 1;
WHILE @Counter < 10
BEGIN
SELECT @Counter AS counter
SET @Counter = @Counter + 1
IF @Counter = 4
BEGIN
GOTO Branch_One --Jumps to the first branch.
END
IF @Counter = 5
BEGIN
GOTO Branch_Two --This will never execute.
END
END
Branch_One:
SELECT 'Jumping To Branch One.' AS message
GOTO Branch_Three; --This will prevent Branch_Two from executing.
Branch_Two:
SELECT 'Jumping To Branch Two.' AS message
Branch_Three:
SELECT 'Jumping To Branch Three.' AS message