我一直在寻找解决此问题的相当长时间的解决方案。但是,找不到任何东西。在不透明区域包含NULL值
我有一个表如下:
Month Col_1 Col_2 Col_3 Col_4 Col_5
---------------------------------------------
Jan NULL NULL 1 1 1
我想UNPIVOT此表序与字段名的另一个表(COL_1,col2的,等等)的加盟。
我的查询:
select Month,Name,value from
TableName
unpivot
(
Value
for Name in (Col_1,Col_2,Col_3,Col_4,Col_5)
) u
当前结果:
这给了我不NULL
值如下:
Month Name Value
-----------------------
Jan Col_3 1
Jan Col_4 1
Jan Col_5 1
预期结果:
我想将NULL
包括在结果中。
Month Name Value
-----------------------
Jan Col_1 NULL
Jan Col_2 NULL
Jan Col_3 1
Jan Col_4 1
Jan Col_5 1
任何帮助,将不胜感激。
愿它帮助,http://stackoverflow.com/questions/1002989/sql-server-include-null-using-unpivot –