CROSS APPLY (
SELECT col = CASE WHEN MAX(col) = MIN(col) THEN MAX(col) ELSE NULL END
CROSS APPLY applies a "function" to each row
of the (virtual) table. In this case, you're calculating a value based on an aggregate of a set consisting of a single record.
You can see this by adding a COUNT(*) to your SELECT clause within the CROSS APPLY. Because the set contains a single record, MAX(col) is necessarily equal to MIN(col) except for the case where col is null. Since you're returning a null value in that case, your CROSS APPLY is equivalent to
CROSS APPLY ( SELECT col )
J. Drew Allen
Business Intelligence Analyst
How to post data/code on a forum to get the best help.How to Post Performance Problems
Make sure that you include code in the appropriate IFCode tags, e.g. [code=sql]<your code here>[/code]. You can find the IFCode tags under the INSERT
options when you are writing a post.