I have 2 stored procedures, each SP returns 2 data set with same schema.
data are like
Stored procedure 1
Table1
ID Name
1 Apple
2 Sony
3 DELL
Table2
OrderID CustomerName
101 AB Stores
202 Sony World
301 PC House
Stored procedure 2
Table1
ID Name
21 HP
32 LG
34 ACCER
Table2
OrderID CustomerName
1301 X-PC World
2202 Your PC House
3301 Ajant Stores
Now I want to merge data like this inside other stored procedure
meargeData1 = SP1.Table1 + SP2.Table1
meargeData2 = SP1.Table2 + SP2.Table2
please suggest me hot I can achieve it .
Solutions like
OPENROWSET(as in the linked question the @PreetSangha included) don’t cope with multiple result sets – they only give you the first result set.Similarly, using a construct such as
INSERT ... EXECwill cope with multiple result sets from stored procedures, but it will store all of the results in a single table – you won’t be able to pull them apart. (There are other issues withINSERT ... EXECthat aren’t worth going into here also)About the only way I can see to do this is by writing some procedural code somewhere in a language that isn’t TSQL. This could either be in whatever client applications you’re building, or a CLR stored procedure. In either case, you’ll have to perform the merge manually.