Your code (as is) worked for me. If you're still having trouble, post some executable sample code as I have to show your problem.declare @t table (id int, int_value int, fund_code int)insert @t select 10001, 1, 1 union allselect 10001, 2, 2 union allselect 10001, 4, 2 union allselect 10001, 8, 2 union allselect 10001, 4, 15 union allselect 10001, 8, 16 union allselect 10001, 8, 12 union allselect 10002, 1, 1 union allselect 10002, 2, 2 union allselect 10002, 4, 15 union allselect 10002, 8, 16 union allselect 10002, 8, 12 SELECT ID, [1] AS coL1, [15] AS coL2, [2] AS coL3, [16] AS coL4, [12] AS coL5FROM @tPIVOT (sum(INT_VALUE) FOR FUND_CODE IN ([1],[2],[15],[16],[12])) AS pORDER BY ID ASCOUTPUT:ID coL1 coL2 coL3 coL4 coL5----------- ----------- ----------- ----------- ----------- -----------10001 1 4 14 8 810002 1 4 2 8 8
Be One with the OptimizerTG