May 5, 2011 at 12:02 am
Hi all,
I have some query regarding sql server 2005.
whenver I try this,I am getting the o/p as
Jumping To Branch One
Jumping To Branch Two
Eventhough the condition fails the in the if condition ,it still goes to the lables.why is it so?please Comment on this
DECLARE @c1 int
DECLARE @c int
SET @c= 1
SET @c1 = 2
IF @c= 0
begin
GOTO Branch_One
end
IF @c1=3
begin
GOTO Branch_Two
end
Branch_One:
print 'Jumping To Branch One'
Branch_Two:
print 'Jumping To Branch Two'
May 5, 2011 at 12:16 am
A goto will jump to a point in code , that code will still be executed as the flow of the program naturally passes it ,that is what has happened here.
May 5, 2011 at 1:47 am
Instead of using GOTO I'd recommend you either include those code sections directly into the related IF block. If there's too much code, use separate sprocs and call those.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply