SQL Server 2005- How to prevent Execution – Goto (T-SQL)

Posted by Joggee | SQL Server 2005 | Friday 14 September 2007 5:51 pm

I am familiar with Goto Command since i was using Visual Basic 6.0.

I wanted to prevent or bypass the execution in a stored procedure and i used the same command in Sql Server 2005.

Some details:

GOTO skip and processing continues at the label.

GOTO statements can be used any where in the procedure and statement block.

EXAMPLEDECLARE @CLASS INT

SET @CLASS = 4
IF @CLASS = 4
GOTO Class4;

Class1:
SELECT ‘Jumping To Class1.’

Class2:
SELECT ‘Jumping To Class2.’
GOTO Class5;

Class3:
SELECT ‘Jumping To Class3.’

Class4:
SELECT ‘Jumping To Class4.’
GOTO Class2;

Class5:
SELECT ‘Jumping To Class5.’

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment