I have a table that consists of several Id’s like this
SELECT * FROM Objects;
ObjectId
---------
1
4
5
and function that produce another table for each ObjectId, for instance
SELECT * FROM dbo.GetNumbers(1) SELECT * FROM dbo.GetNumbers(4) SELECT * FROM dbo.GetNumbers(5)
NumberId NumberId NumberId
--------- --------- ---------
40 11 12
45 2
18
How can I get the cartesian product of original table with the tables produced by functions without using cursors?
SELECT ???
ObjectId NumberId
---------------------
1 40
1 45
4 11
4 2
4 18
5 12
Don’t you just want to do?
If you want to include
Objectsthat have noGetNumbersresults useOUTER APPLY.A simple way of looking at it is,
CROSS APPLYis anINNER JOINto a TVF,OUTER APPLYis aLEFT OUTER JOINto a TVF.You shouldn’t confuse these with
CROSS JOINwhich has nothing specific to do with functions and is used to provide the Cartesian Product of two sets, which is not what you want here.