日期:2014-05-18  浏览次数:20394 次

这个问题能用PIVOT解决吗?
Id | Type | Name | Value
-------------+-------+--------------+-------------
F0000000FG | FD | SEDOL | 4779823
F0000000FG | FD | ExternalId | 6789

->


Id | Type | SEDOL | ExternalId
-------------+-------+----------+-------------
F0000000FG | FD | 4779823 | 6789


------解决方案--------------------
--确定列数为以上4列时
select 
*
from 

pviot
(max([value] for Name in([SEDOL],[ExternalId])))tmp
------大于4列时
select 
*
from 
(select 
ID,type,Name, [values]
from 
T )T2
pviot
(max([value] for Name in([SEDOL],[ExternalId])))tmp