Question

This is a little tricky to describe, but hopefully there is a solution.

I have a UDF which takes an ID and returns a table. Is there a way I can do a SELECT for these IDs and perform a UNION of the UDF results? For example;

To get the IDs;

SELECT [ID] FROM [TableOfIDs]

To get the object properties from an ID;

SELECT * FROM GetObjectProperties(@ID)

But how do I combine the two? That is, to do a union of the UDF results from a query for the IDs?

I hope that makes sense!

Was it helpful?

Solution

You need to use APPLY:

SELECT TT.* 
FROM [TableOfIDs] AS T CROSS APPLY GetObjectProperties(T.ID) AS TT;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top