Fastest Way to Count Distinct Values in a Column, Including NULL Values
I think you should try to keep the number of table scans down and count all columns in one table in one go. Something like this could be worth trying.
;with C as( select dense_rank() over(order by Col1) as dnCol1, dense_rank() over(order by Col2) as dnCol2 from YourTable)select max(dnCol1) as CountCol1, max(dnCol2) as CountCol2from C
Test the query at SE-Data