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
 Transact-SQL (2000)
 Join Table to Stored Proc Results

Author  Topic 

coderdude
Starting Member

24 Posts

Posted - 2004-09-08 : 12:36:16
I have a stored proc that takes three parameters and returns a set of rows. I want to join that set of rows to another query that I am performing (like a sub-select). I realize that following syntax is not possible, however, I think it gets across the idea of what I am trying to do:

SELECT *
FROM table1 INNER JOIN (EXEC myStoredProc 1, 2, 3) table2
ON table1.id = table2.id

Do I have to somehow dump the results of the stored proc to a temp table first? If so how? Or is there a better way?

nr
SQLTeam MVY

12543 Posts

Posted - 2004-09-08 : 12:50:15
Do I have to somehow dump the results of the stored proc to a temp table first?
Yes

You could also make the sp into a table valued function or an openquery on another connection but using a temp table is probably best.

==========================================
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

coderdude
Starting Member

24 Posts

Posted - 2004-09-08 : 13:06:14
What are the downsides to using a table valued function?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-08 : 13:10:49
u can't modify data in the database in functions. no inserts or updates. otherwise it's preety cool.
but this is allowed among other things:
- INSERT, UPDATE, and DELETE statements modifying table variables local to the function.
- EXECUTE statements calling an extended stored procedures.

look up BOL for more info.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

coderdude
Starting Member

24 Posts

Posted - 2004-09-08 : 16:26:07
Thanks guys!
Go to Top of Page
   

- Advertisement -