Wednesday, January 13, 2010

OUTER APPLY and CROSS APPLY in SQL SERVER

The APPLY operator uses the results from a query as input to apply a table-valued
Function to each row in the result set.
The APPLY operator has two forms, CROSS APPLY and OUTER APPLY.
CROSS APPLY returns only rows from the left output, which produces data from the table-valued function (matches row between the table and function).
OUTER APPLY returns all rows from the left, outer table. Like an OUTER JOIN statement.
Let's see this Example:



Summary:
OUTER APPLY returns all rows from the outer table along with the results returned by
the function when rows match, while CROSS APPLY returns only the rows from the
outer table where a match exists within the function results.

No comments: