Friday, March 9, 2012

Join with Stored Procedure?

I have a stored procedure A that returns results in this format:

ID
--
1
2
...

I want to make a procedure B that, by joining with the result obtained from A (A INNER JOIN B on A.ID = B.ID), returns a table like this:

ID Title
---
1 Title 1
2 Title 2

But SQL server says invalid object name for A when I try to run B... Assuming stored procedures cannot be "joined", what can I do to obtain similar results?My understanding is that you dont need the first sp. Try this:

Select b.id, b.name where b.id in (select a.id from a)

(Ever tried Select b.id, b.name where b.id in (exec a))

- OR -

Change the type of your first stored procedure to a function that returns table. See help or ask a guru. Then you will (hopefully) be able to do things such as:

select * from a() inner join b on a().id = b.id|||Thanks, using function solved the problem :)

No comments:

Post a Comment