Click here to Skip to main content
15,902,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have two Stored Procs, I want to execute the first Stored Proc inside the second Stored Proc and get the resultset.

Is this possible in SQL 2005?

Thank you.
Posted

YES Its possible.


SQL
CREATE PROCEDURE FIRSTPROC
AS
BEGIN
    SET NOCOUNT ON
        EXEC SECONDPROC
    SET NOCOUNT OFF
END
 
Share this answer
 
Comments
akosidab 23-May-13 1:43am    
How will I be able to get the result set of the secondproc?
Arun Vasu 23-May-13 3:20am    
while you running firstProc you will get the result.

if you want that secondproc result use table variable and insert the result set into that. after that you can manipulate that.

CREATE PROCEDURE FIRSTPROC
AS
BEGIN
SET NOCOUNT ON
DECLARE @TABLE TABLE(COL1 INT, COL2 NVARCHAR(10))

INSERT INTO @TABLE
EXEC SECONDPROC

SELECT * FROM @TABLE
SET NOCOUNT OFF
END
_Amy 23-May-13 1:49am    
+5!
Thanks to all your solution but it doesnt work.

I found a good solution:

SQL
insert into #table_temp
    exec [ap_StoreProc] @Param1;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900