Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change data from row to culumn
Message
From
13/04/2005 00:32:41
 
 
To
09/04/2005 21:15:54
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01002016
Message ID:
01004040
Views:
18
Further more,you may do it with a more flexible trick like the sample below,
create table tbl (F_NM1 int,F_NM2 int,F_QTY int)
insert tbl select 1,101,1000
union all select 1,102,2000
union all select 1,103,99
union all select 2,101,3000
union all select 2,102,4000
union all select 2,103,599
go

declare @s varchar(8000)
set @s=''
select @s=@s+',[F_'+cast(F_NM2 as varchar)
 +']=sum(case F_NM2 when '+cast(F_NM2 as varchar)
 +' then F_QTY else 0 end)'
from tbl
group by F_NM2
exec('select F_NM1'+@s+' from tbl group by F_NM1')
go
HTH
Steven
Steven
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform