Hmm, if any column has a NULL value, it can't be equal to anything. Concatenating null should make the expression null according to SQL. MSSQL is weird... The following counts nulls distinctly, hope that this is the solution. count(distinct case when col1 is null or col2 is null then null else col1 || '\0' || col2 end) + count(case when col1 is null or col2 is null then 1 end) |