SQL UNPIVOT命令-如何获取2列

时间:2019-02-08 16:02:47

标签: unpivot

我无法使脚本正常工作。

我想获得另一列有关qty1,qty2等的描述 我在这里做错什么了,这正确地为每列生成了一条记录,但是我需要第二个具有原始名称的列?

        SELECT sty_qual, BF_MAT_CHAR_VAL, loc_num, qty -- how to get size in here??
from 
(
select  sty_qual, BF_MAT_CHAR_VAL, loc_num, 
 qty1 = isnull(qty1,0)
 , qty2 = isnull(qty2,0) 
 , qty3 = isnull(qty3,0) 
 , qty4 = isnull(qty4,0) 
 , qty5 = isnull(qty5,0) 
 , qty6  = isnull(qty6,0) 
 , qty7  = isnull(qty7,0) 
 , qty8  = isnull(qty8,0) 
 , qty9  = isnull(qty9,0) 
 , qty10  = isnull(qty10,0)
 , qty11  = isnull(qty11,0)
 , qty12  = isnull(qty12,0) 

from Snapshot_STY_QUAL  
where STY_QUAL = '939353'
and BF_MAT_CHAR_VAL = 'GRN-MINT'
and LOC_NUM = 70275   
) p

unpivot

(qty for sty_id in
(qty1, qty2, qty3, qty4, qty5, qty6, qty7, qty8, qty9, qty10, qty11, qty12)
         ) as unpvt1

0 个答案:

没有答案