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 2000 Forums
 Transact-SQL (2000)
 Exit Sub Equivalent

Author  Topic 

Jonny1409
Posting Yak Master

133 Posts

Posted - 2007-12-20 : 05:57:39
Hello,

Is there a SQL equivalent of the VB code 'EXIT SUB' ?

Basically I want to check if a row exists in a certain table, and if it doesn't then insert it, but if it does, exit the stored procedure.

Thanks,

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-20 : 06:17:54
Use RETURN statement.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-20 : 06:27:41
or use IF statement

If not exists(select * from table where...)
Begin
---your code to insert
End

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

georgev
Posting Yak Master

122 Posts

Posted - 2007-12-20 : 08:34:27
Just run with me on this...

...would it not be more efficient to swap the NOT EXISTS for an EXISTS and ELSE statement?




George
<3Engaged!
Go to Top of Page
   

- Advertisement -