Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 If a condition matched how to go to bottom of scri

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2015-01-22 : 14:32:09
I have teh below logic within my Sp, if condition matched i want to go to last without performing any transaction.

is it return?

if @ContractID=0
begin
How to go to last line of sp so that nothing gets executed on this sp call, since @contractid=0
End


Thanks a lot for the helpful info.

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2015-01-22 : 14:41:35
Can i use
GOTO SkipActions



and at below at teh end:

SkipActions:
PRINT 'An error was encountered processing the transaction.'
GO
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-01-22 : 14:56:08
You can use GOTO, however that's considered bad programming. Instead just use RETURN to exit the stored proc.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-01-22 : 14:57:00
if @ContractID=0
begin
PRINT 'An error was encountered processing the transaction.' --you should not use PRINT, instead use RAISERROR
RETURN
end

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-23 : 06:06:12
If you want to use goto method this is the code
if @ContractID=0
begin
GOTO SkipActions
End

SkipActions:
PRINT 'An error was encountered processing the transaction.'
GO




Regards
Viggneshwar A
Go to Top of Page

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-23 : 06:06:24
if @ContractID=0
begin
Raiserror('An error was encountered processing the transaction.', 16, 1)
End

Regards
Viggneshwar A
Go to Top of Page
   

- Advertisement -