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)
 JOINing the results of two stored procs

Author  Topic 

aggiekevin
Starting Member

14 Posts

Posted - 2007-06-11 : 23:07:28
I want to be able to execute two stored procedures (which require parameters be passed into them) and JOIN their results.

(EXEC sp_mystoredproc1 @param1) sp1
INNER JOIN (EXEC sp_mystoredproc2 @param2) sp2
ON sp1.ID = sp2.ID


I know the example I gave above is not possible, but hopefully it demonstrated what I want to do. I am new to SQL Server and not sure how to implement this kind of functionality...

Thanks!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-11 : 23:10:47
you can't do that. insert the result of the stored procedure into temp tables and INNER JOIN the temp table

insert into #temp1 ( . . .) exec sp_mystoredproc1 ...
insert into #temp2 ( . . .) exec sp_mystoredproc2 ...
select *
from #temp1 t1 inner join #temp2 t2 on t1.id = t2.id






KH

Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-11 : 23:10:51
You can get the results of the procs into 2 temp tables and join them via a query.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-11 : 23:11:43



Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-11 : 23:12:27
4 secs
the sniped is slower

KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-12 : 09:15:04
Also note that you need to create temp tables whose structure is similar to the one that SP returns

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -