行转列

梦想的初衷 提交于 2019-11-26 08:14:42

ALTER PROCEDURE [dbo].[proc_Distribute_Report]
@ParamBillMonth VARCHAR(150)
AS
BEGIN
PRINT @ParamBillMonth
DECLARE @sql VARCHAR(MAX)
SELECT @sql = ISNULL(@sql + ',', '') + [TCT]
FROM tb_20120720
WHERE billMonth LIKE '' + @ParamBillMonth + '%'
GROUP BY [TCT]

PRINT @sql
 

EXEC ( ' SELECT Efficiency,PIOT, Reliability,Usability,Functionality,RT,PRT,Stability,FactoryTest,SonyIOTFIOT ,TPOMgmtsupport, TokyoPRT, TPOCommonFunction,PRTBeijingOutsourcing, CVFOTA , CAV, LV ,OMVTPO, FTBeijing, FTSasken , FTHK, LundSasken,OMVEMEABJOrangeTMC, TCTApplicationsTest, FTLAM,FTNAM ,TokyoTCT,FT,RAT, TCTBeijingOutsourcing FROM ( SELECT TCT ,
SUM(TotalCost) AS TC
FROM tb_20120720
WHERE BillMonth = ''201209''
GROUP BY TCT
) A PIVOT( SUM(A.TC) FOR A.TCT IN ('+@sql+')) AS PVT ')






END

转载于:https://www.cnblogs.com/konglingxing/archive/2012/10/16/2726182.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!