create table #temptab
(
col1 int ,
col2 varchar(10),
col3 varchar(10),
col4 int
)
insert into #temptab
select 1, 'AA', 'A001', 300
insert into #temptab
select 2, 'AA', 'B001', 200
insert into #temptab
select 3, 'AA', 'C001', 450
insert into #temptab
select 4, 'BB', 'A001', 230
insert into #temptab
select 5, 'BB', 'E001', 300
insert into #temptab
select 6, 'CC', 'A001', 200
insert into #temptab
select 7, 'CC', 'A002', 300
select COL2, ISNULL([A001],0),ISNULL([A002],0),ISNULL([B001],0),ISNULL([C001],0),ISNULL([E001],0) from
(select col2, col3, col4
from #temptab) tab1
PIVOT (max(col4) FOR COL3 IN([A001],[A002],[B001],[C001],[E001]) ) TAB2
I think this should give u a clear picture....