see below for full illustration of sample data you posteddeclare @test table(id int,charge int,amnt int)insert @testvalues(1, 11, 33),(1, 12, 34), (1, 16, 98),(2, 11, 12),(2, 16, 12),(2, 12, 30), (2, 15, 25)SELECT id,COALESCE([11],0) AS [11],COALESCE([12],0) AS [12],COALESCE([15],0) AS [15],COALESCE([16],0) AS [16]FROM @test tPIVOT (SUM(amnt) FOR charge IN ([11],[12],[15],[16]))poutput----------------------------------------id 11 12 15 16----------------------------------------1 33 34 0 982 12 30 25 12
If its not working for you then i'm sure you've some other columns in table or part in query which you've not shown as so farUnless you give us full information, we cant provide you exact solution for your scenario. So please post any additional information that's applicable to your scenario------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/