SQL Server – Include NULL using UNPIVOT
To preserve NULLs, use CROSS JOIN … CASE: select a.ID, b.column_name , column_value = case b.column_name when ‘col1’ then a.col1 when ‘col2’ then a.col2 when ‘col3’ then a.col3 when ‘col4’ then a.col4 end from ( select ID, col1, col2, col3, col4 from table1 ) a cross join ( select ‘col1’ union all select ‘col2’ union … Read more