SQL complex unions

368 Views Asked by At

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!

1

There are 1 best solutions below

0
On BEST ANSWER

You need to use APPLY:

SELECT TT.* 
FROM [TableOfIDs] AS T CROSS APPLY GetObjectProperties(T.ID) AS TT;