Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Contagem de colunas não nulas em cada linha

select
    T.Column1,
    T.Column2,
    T.Column3,
    T.Column4,
    (
        select count(*)
        from (values (T.Column1), (T.Column2), (T.Column3), (T.Column4)) as v(col)
        where v.col is not null
    ) as Column5
from Table1 as T