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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Exit a Stored Procedure 1

Status
Not open for further replies.

jw2000

Programmer
Aug 12, 2005
105
US
Inside my stored procedure, I have the following logic:

if exists(select * <<1>>)
begin
select * ...
end

else if exists(select * <<2>>)
begin
select 'no records'
end

else
select 'you do not have access'
end


Basically I want to return records from <<1>> if there are records. If not, I want to see if <<2>> returns records. If <<1>> returns records, I want to exit the stored procedure, and not go into <<2>> or the else part.

If <<1>> does not exist, and <<2>> exists, I want to return 'no records' and exit the stored procedure. If else, I want to return 'you do not have access'.


 
I added return, but I cannot get to the else part.


if exists(select * <<1>>)
begin
select * ...
return
end

else if exists(select * <<2>>)
begin
select 'no records'
return
end

else
select 'you do not have access'
end


 
what do you mean you cannot get the else part? If you hit the final else, the message will pring the the proc finishes executing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top