## CROSS APPLY

 Author Message Minnu Hall of Fame Group: General Forum Members Points: 3271 Visits: 950 CROSS APPLY ( SELECT col = CASE WHEN MAX(col) = MIN(col) THEN MAX(col) ELSE NULL END ) Andy Hyslop SSCertifiable Group: General Forum Members Points: 5113 Visits: 3060 And the question is!? ==========================================================================================================================A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe Jeff Moden SSC Guru Group: General Forum Members Points: 509101 Visits: 44288 Skanda (10/17/2012)CROSS APPLY ( SELECT col = CASE WHEN MAX(col) = MIN(col) THEN MAX(col) ELSE NULL END )You REALLY need to get out of the habit of editing your posts. Replacing the question with the answer does no one reading the thread any good. Even you won't have a clue as to what the question actually was in a couple of weeks so you've destroyed your own valuable reference. --Jeff ModenRBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair Helpful Links:How to post code problemsHow to post performance problemsForum FAQs drew.allen SSC-Dedicated Group: General Forum Members Points: 36854 Visits: 13667 Skanda (10/17/2012)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 )`Drew J. Drew AllenBusiness Intelligence AnalystPhiladelphia, PAHow to post data/code on a forum to get the best help.How to Post Performance ProblemsMake sure that you include code in the appropriate IFCode tags, e.g. [code=sql][/code]. You can find the IFCode tags under the INSERT options when you are writing a post.