views:

1164

answers:

4

i was hoping to be able to do something like this:

declare @label varchar
set @label = 'label_1'
goto @label

label_1:

label_2:

of course, sql server gives me an incorrect syntax error... so i was wondering if i can still do this with a slightly different syntax?

+2  A: 

Why not simply use an if/else?

anon
If he's using SQL2k, probably is for error processing - as copying-paste all error processing in all necessary places is really worse than goto.
Fabricio Araujo
A: 

not tested but does exec("goto "+@label) work ?

Learning
A: 

You can only do this if you dynamically build the SQL statement.

GOTOs are best avoided though - mainly for code readability.

Keith
A: 

As far as I know, you cannot parameterize GOTO. You can do that if you use Dynamic SQL.

Fabricio Araujo