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
来源:https://blog.csdn.net/weixin_30276935/article/details/98770161