Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change data from row to culumn
Message
De
13/04/2005 00:32:41
 
 
À
09/04/2005 21:15:54
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01002016
Message ID:
01004040
Vues:
25
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform