简体   繁体   中英

Store multiple data sets from stored procedure in SQL Server 2008 R2?

This is how I store dataset in a table from a procedure that returns a single dataset.

 CREATE TABLE #TEMP (amount DECIMAL(18, 2), extra VARCHAR(50))  

 INSERT INTO #TEMP (extra, amount)
     EXEC sp_proc @para1, @para2, @para3

Now can I store dataset from procedures that return two or more tables. If possible how can I do that?

I don't intend to create temporary global tables as I would have to alter multiple procedures. Can I do so without altering the procedure?

Now Can i store dataset from procedures that return two or more tables. If possible how can i do that?

No, is not possible, at least not directly. One of the many limitations of INSERT ... EXEC . I recommend you modify the stored procedure to be split into individual separate stored procedures, each returning its own result set.

Indirectly you can do it by switching control outside of T-SQL, eg. by runing it via a SQLCLR procedure.

You don't store multiple table result from SP in other tables. You have to create separate SP for that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM