Please see the query below. This is basically a count of different columns in a table variable. Initially the query wasn't commented, and so was an outer and inner query. I did this because I THOUGHT that SQL would re-calculate all the sums in the last column. After removing the outer query and performing the whole thing in a single query, I don't think there's any difference. From the basics I can see in the Client Statistics it seems similar.Am I correct in thinking this? Does SQL really 'see' that the data required for the last column's calculations has already been done, and just re-use them?--SELECT-- q.*,-- (q.count1 - q.count2) as [total] -- removed from here into formerly sub-query--FROM-- ( -- Sub-query does initial counts SELECT linkID, COALESCE(COUNT(linkID), 0) as [count1], COALESCE(COUNT(notAppCol), 0) as [count2], COALESCE(COUNT(linkID), 0) - COALESCE(COUNT(notAppCol), 0) as [count3] -- no more resources used if performed here? FROM @tbl_results GROUP BY linkID-- ) as q
