0

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 .

Neeraj Kumar Gupta
  • 2,157
  • 7
  • 30
  • 58

2 Answers2

0

Collect the results of both procedures into a into a temporary table like in question.

Insert results of a stored procedure into a temporary table

Community
  • 1
  • 1
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
0

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 ... EXEC will 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 with INSERT ... EXEC that 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.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448