In SQL 2005, I had to write a Query in which a TVF(Table Valued Function) should be joined with a Table. The TVF had a Parameter which should be joined to the Table's Column
TVF - MyFunction(@ID)
Table - MyTable (with a Column ID)
Here the MyTable.ID should be joined with the MyFunction(@ID) to produce the results. The normal JOIN will not work in this case. This should be done by using CROSS APPLY feature:
SELECT * FROM MyTable T CROSS APPLY MyFunction(T.ID)
CROSS APPLY = Table INNER JOIN TVF
In case of LEFT JOINing use 'OUTER APPLY' like this:
SSELECT * FROM MyTable T OUTER APPLY MyFunction(T.ID)
OUTER APPLY = Table LEFT OUTER JOIN TVF
Note: No need to USE 'ON' clause
Friday, March 13, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment