Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Procedure returns multiple tables - Insert results into tables

I have a procedure that returns multiple tables; eg:

PROCEDURE Something AS
BEGIN
 SELECT 1,2,3
 SELECT 4,5
 SELECT 9,10,11
END

I would like to take each table from the result and insert it into a series of tables/temp tables - one for each record set.

Is this possible?


2 Answers

You could create the temporary tables within the stored proc and push the records into that. If you are using the same session , the table would be available after the stored proc is finished.

Or you could create the temp tables before hand and call the sp to populate them.

like image 148
Learning Avatar answered Sep 17 '26 18:09

Learning


if you Union the results together they would come out as one result set.

your second query only has 2 columns but this would need to be resolved either way as you put it into a table.

like image 24
Jeff Martin Avatar answered Sep 17 '26 17:09

Jeff Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!