emily-1119612
SSCarpal Tunnel
Points: 4166
More actions
August 14, 2009 at 9:29 am
#224894
Thanks to anyone who can help. My assumption is that column #test.Type will only be 2 values, A or B.
CREATE TABLE #test
(
Account int,
Type char(1),
Amount int
)
INSERT INTO #test
SELECT 1,'A',4
UNION
SELECT 1,'B',2
SELECT 1,'A',5
SELECT 2,'B',5
SELECT 2,'B',8
SELECT 2,'A',1
SELECT * FROM #test
DROP TABLE #test
--Desired results
--First line is header
Account,TypeA,TypeB
1,9,2
2,1,13
Lynn Pettis
SSC Guru
Points: 442467
August 14, 2009 at 9:55 am
#1039486
Not too hard, here is the code I came up:
select
Account,
sum(case when Type = 'A' then Amount else 0 end) as TypeA,
sum(case when Type = 'B' then Amount else 0 end) as TypeB
from
#test
group by
Account;
August 14, 2009 at 10:31 am
#1039527
Perfect thanks. 🙂
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply