Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Need help building query

Author  Topic 

gsi
Starting Member

4 Posts

Posted - 2003-03-27 : 14:01:14
Hello All,
I am novice so need some help to build a query in MSSQL 2000. Below are the details


A table contains the following fields

prog_id
item_id
type
amount

prod_id and item_id are the primary keys here


Rows are to be summarized by program_id, and depending on the type, it needs to be summed up
under total-A or Other

Case type='A' then sum it up as total-A
else any other type sum it up as Other


results should be as follows:

Prog_id total-A Other
------------------------------------------
123 $100.00 $300.00

456 $150.00 $200.00


Any help will be appreciated


Thanks
gsi



Edited by - gsi on 03/27/2003 14:10:55

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-03-27 : 14:25:43
select program_id,
SUM(CASE WHEN type='A' THEN amount else 0 end) as TotalA,
SUM(CASE WHEN type<>'A' THEN amount else 0 end) as Other
from
yourtable
group by program_id

- Jeff
Go to Top of Page

gsi
Starting Member

4 Posts

Posted - 2003-03-27 : 14:40:29
Thanks Jeff, that worked

Go to Top of Page
   

- Advertisement -