return
- In stored procedure after return statement can we execute another stored procedure?
Satish
Answers
- Satish,Not sure exactly what you are asking. Hope this helps to understand the behavior.
create procedure dbo.SP2 as select 'I am SP2' return go create procedure dbo.SP1 as select 'I am SP1' return exec dbo.SP2 go create procedure dbo.SP0 as select 'I am SP0' If 0 > 1 return exec dbo.SP2 go exec dbo.SP1 go exec dbo.SP0
| Sankar Reddy | http://sankarreddy.spaces.live.com/ |- Marked As Answer bySatish Kumar Thota Sunday, June 28, 2009 10:45 AM
All Replies
- Satish,Not sure exactly what you are asking. Hope this helps to understand the behavior.
create procedure dbo.SP2 as select 'I am SP2' return go create procedure dbo.SP1 as select 'I am SP1' return exec dbo.SP2 go create procedure dbo.SP0 as select 'I am SP0' If 0 > 1 return exec dbo.SP2 go exec dbo.SP1 go exec dbo.SP0
| Sankar Reddy | http://sankarreddy.spaces.live.com/ |- Marked As Answer bySatish Kumar Thota Sunday, June 28, 2009 10:45 AM
You can have a super stored procedure which executes several stored procedures. Note however, error control becomes tricky if you setup nested stored procedures structure.
Kalman Toth, SQL Server & BI Training, SSAS, SSIS, SSRS; http://www.SQLUSA.com- not clear of what are you asking...
create procedure sp1
as
begin
exec proc sp2
exec proc sp3
...
..
end
This is the only possible method as per my learning...hav 7 days experience with t-sql - No:
"The RETURN statement unconditionally terminates a query, stored procedure, or batch. None of the statements in a stored procedure or batch following the RETURN statement are executed."
http://msdn.microsoft.com/en-us/library/ms187009.aspx
Plamen Ratchev- Proposed As Answer byNaom Sunday, June 28, 2009 6:22 PM
- Why would you want to? the point of the RETURN statement is to stop the stored procedure. T-SQL code is executed single threaded (queries can be parallelised internally for individual operators, but not other statements). What are you trying to accomplish?
http://drsql.spaces.msn.com


