Working with GoTo block in Sql Server.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 1220
GoTo block in Sql Server is same as GoTo block in C#. It means it jumps to to defined block.In our code,if @rec_cnt variable value is greater than 0,then it jumps to the exit block.
and inside exit block,it will print value,We have to define GoTo keyword followed by name or label name and we have to give colon(:) in GoTo name block.

Declare @rec_cnt Int;
Select @rec_cnt = Count(*) From Employee_Master Where Employee_Id = 1;

If(@rec_cnt > 0) GoTo ExitBlock
GoTo Steps
ExitBlock:
Print 'ExitBlock';
Steps:

You can give your own condition for GoTo Statement.

Comments or Responses

Login to post response