server sql 列转横
功能:将一条记录,转换成 多行
PS :空记录,未生成记录
示例:
转后效果:
语句:
select * from (
select
b.START_VAL
,b.ADD_VAL
,b.CUR_DIST
,b.LES_VAL
,b.BAC_VAL
,b.OUT_VAL
,b.OTH_LES_VAL
,b.FINA_VAL
from cgenius..STK_PVSAIPM_main a inner join cgenius..STK_PVSAIPM_SUB b
on a.seq=b.p_seq
where a.isvalid=1 and b.isvalid=1
and b.SEQ=1
)t1 UNPIVOT (Orders FOR Employee IN (START_VAL, ADD_VAL, CUR_DIST, LES_VAL, BAC_VAL, OUT_VAL, OTH_LES_VAL, FINA_VAL )
)AS unpvt;