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

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.’

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s