开发者

SQL complex unions

开发者 https://www.devze.com 2023-02-07 19:56 出处:网络
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 U

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 fo开发者_开发知识库r the IDs?

I hope that makes sense!


You need to use APPLY:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号