Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 union of two sp results

Author  Topic 

akashenk
Posting Yak Master

111 Posts

Posted - 2007-02-01 : 04:50:28
Can anyone help me get the UNION of the the result of two EXEC statements within my SP. So, for example, in my Store Procedure, I call another stored procedure twice using EXEC to get two groups of data and I want to return the union of these.

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2007-02-01 : 04:58:06
Create a temp table and put the results of both SPs into it then do a distinct on the result.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

akashenk
Posting Yak Master

111 Posts

Posted - 2007-02-01 : 05:05:04
I think I know how to create a temp table, but how do I place the results of the SPs into it?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-02-01 : 05:14:39
insert #a exec mysp


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

akashenk
Posting Yak Master

111 Posts

Posted - 2007-02-01 : 05:18:47
Can I do the same with a table variable instead of a temporary table?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-01 : 05:34:56
no. You can't


KH

Go to Top of Page

akashenk
Posting Yak Master

111 Posts

Posted - 2007-02-01 : 05:47:51

Thanks for your help.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-02-01 : 06:09:39
Actually with v2005 you can.
It would take you a couple of minutes to try it for yourself.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

akashenk
Posting Yak Master

111 Posts

Posted - 2007-02-01 : 06:16:59
got it... thanks.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-01 : 07:08:24
quote:
Originally posted by nr

Actually with v2005 you can.
It would take you a couple of minutes to try it for yourself.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.



Oh . . did not know that


KH

Go to Top of Page
   

- Advertisement -