I have a database that I need to run a group by with. I need to add up all the records by Department. Typical data:
Amount Department
10 01ED
14.50 01
10.44 02GX
100.00 01GX
300.00 03ED
400.00 02
And so on. The departments are the first two characters..
01, 02, 03, etc.
I'd like to get results like this:
124.50 01
410.44 02
300.00 03
I thought a select like this:
select sum(Amount) as Amt, (Case Dept when like '01%' then 01 when like '02%' then 02, when like '03%' then 03 else other end) as DeptCode
From Invoice
But Like doesn't work in a case statement. Any ideas?
Amount Department
10 01ED
14.50 01
10.44 02GX
100.00 01GX
300.00 03ED
400.00 02
And so on. The departments are the first two characters..
01, 02, 03, etc.
I'd like to get results like this:
124.50 01
410.44 02
300.00 03
I thought a select like this:
select sum(Amount) as Amt, (Case Dept when like '01%' then 01 when like '02%' then 02, when like '03%' then 03 else other end) as DeptCode
From Invoice
But Like doesn't work in a case statement. Any ideas?