Counting the Not-Directly-Countable in T-SQL

A Practical Pattern for Trustworthy Distinct Counts, Subtotals, and Grand Totals