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
 Transact-SQL (2000)
 Query Question!

Author  Topic 

billyjeong
Starting Member

1 Post

Posted - 2003-04-10 : 11:57:13
I have some raw date. I'll make some query that it has CASE caluse.
It's very difficult. can u have some soultions.

Raw Date

Date Code Amount
---------------------------------------------
03/01/2003 20001 570.00
03/01/2003 20002 980.00
03/01/2003 30001 180.00
03/02/2003 30001 800.00
03/02/2003 20002 800.00


Output Result

Date 20001 20002 30001
------------------------------------------
03/01/2003 570.00 980.00 180.00
03/02/2003 800.00 800.00




claire
Starting Member

19 Posts

Posted - 2003-04-10 : 12:14:12
create table table1(Date varchar(10),Code int ,Amount money)
go
insert into table1 select '03/01/2003',20001,570
insert into table1 select '03/01/2003',20002,980
insert into table1 select '03/01/2003',30001,180
insert into table1 select '03/02/2003',30001,800
insert into table1 select '03/02/2003',20002,800
go

select date,
sum(case code when 20001 then amount else 0 end)as '20001',
sum(case code when 20002 then amount else 0 end)as '20002',
sum(case code when 30001 then amount else 0 end)as '30001'
from table1
group by date
go

Go to Top of Page
   

- Advertisement -