Read this it will give you some idea.
http://blog.sqlauthority.com/2007/05/07/sql-server-20052000-examples-and-explanation-for-goto/[
^]
In the first code snippet the value of a is > b so
GOTO Greater
this is executed.
so
Greater: SELECT @a
this will get executed. after that next line is executed which is
Lesser: SELECT @b
.
since there is no statement to return after executing the code in label greater, the label lesser will get executed.
In the second code snippet when
@Counter
becomes 3 then
IF @Counter = 3 GOTO Branch_One
is executed and the cursor comes out of while loop.
under label
branch one
these 2 statements are there
SELECT 'Jumping To Branch One.'<br />
GOTO Branch_Three;<br />
in the above code after select,
GOTO Branch_Three;
statement is there so cursor will execute the statements under label
branch_three
after finishing the execution of label
branch_three
no statement is there to execute.
as the cursor came out of while loop
branch_Two
will never get executed.
I hope you understood.