我一直在尋找解決此問題的相當長時間的解決方案。但是,找不到任何東西。在不透明區域包含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 –