APPLY is a line-by-line statement that allows APPLY use either a function or a subquery on each row of previous tables. Therefore, it is very useful in situations where
- you need the last record / maximum / minimum record from B from each record in A
- you need to run a table function for each entry in A
Yes, this can replace REGISTER, but it would do terribly when a normal REGISTER would work, because you force SQL Server to use line by line of statements, and not install based on JOIN.
The difference between CROSS APPLY and OUTER APPLY is the same as the difference between INNER JOIN and OUTER JOIN. Basically, CROSS APPLY deletes the original record if the function / subquery to which it is applied returns 0 records. OUTER APPLY saves the source record.
Read more: Using Apply (msdn)
source share