Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TSQL GOTO statement

Status
Not open for further replies.

Naoise

Programmer
Dec 23, 2004
318
IE
I have something along the lines of....

UPDATE....

IF @@ERROR <> 0
BEGIN
GOTO ERROR_HANDLER
END
ELSE
BEGIN
UPDATE ...

IF @@ERROR <> 0
BEGIN
GOTO ERROR_HANDLER
END
ELSE
BEGIN
GOTO SUCCESS_NOTIFICATION
END
END

ERROR_HANDLER: PRINT 'ERROR'

SUCCESS_NOTIFICATION: PRINT 'SUCCESS'

When it hits a GOTO SUCCESS_NOTIFICATION it prints out one message, ie SUCCESS. However when it hits a GOTO ERROR_HANDLER it prints out 2 messages, both ERROR and SUCCESS. It seems that when it hits the ERROR_HANDLER it continues to execute the SUCCESS_NOTIFICATION too. Can I have 2 labels in a TSQL statement?? or is this simply a layout issue? Thanks in advance.
 
Code:
ERROR_HANDLER: PRINT 'ERROR'
GOTO ENDOFPROC

SUCCESS_NOTIFICATION: PRINT 'SUCCESS'

ENDOFPROC:

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top