行转列

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

posted @ 2012-10-16 15:52  Kong, Star  阅读(188)  评论(0编辑  收藏  举报