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 2000 Forums
 SQL Server Development (2000)
 Unions on stored procedure results

Author  Topic 

jgrieco
Starting Member

1 Post

Posted - 2002-06-19 : 12:01:32
Hi,
Is there any way to use union with results from stored procedures?
Example:

create procedure dbo.sp_union_test_top
(@val1 int, @val2 int)
as
exec sp_union_test_1 @val1, @val2
union
exec sp_union_test_2 @val1, @val2
go

Both stored procedures return the same columns, but the internal queries are different. I am currently using dynamic sql statements but it is getting messy, I'd like to put the code for the subqueries in separate sprocs and union the results together. I can't get it to work and was wondering if it is even possible before I invest more time in it.

Thanks,
Joe

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-06-19 : 12:36:12
Not really. You'd have to create a loopback linked server (linked server that links to itself) and wrap each procedure in and OPENQUERY, but the performance won't be all that great. You're better off just incoporating the union in a single procedure.

Go to Top of Page
   

- Advertisement -