Here is a similar way:declare @yourTable table(div int, fielda char(1), fieldb int)insert @yourTableselect 01, 'A', 05 union allselect 01, 'A', 10 union allselect 01, 'B', 30 union allselect 02, 'B', 15select div ,sum(case when fielda = 'A' then fieldb else 0 end) as [Sum(A)] ,sum(case when fielda = 'B' then fieldb else 0 end) as [Sum(B)]from @yourTablegroup by divoutput:div Sum(A) Sum(B)----------- ----------- -----------1 15 302 0 15
Be One with the OptimizerTG