将 Header 值转换为具有值的行

Convert Header value as row with value

OwnerID  ShortList DisplayList  QuickStart ShortDateID LongDatetID
-------  --------- -----------  ---------- ----------- -----------
280      10        10           1          4           17

输出:

Key            value
-----------    -----
OwnerID        280              
ShortList      10               
DisplayList    10               
QuickStart     1                
ShortDateID    4                
LongDatetID    17

使用逆轴

SELECT key, value
FROM   
   (SELECT OwnerID, ShortList, DisplayList, QuickStart, ShortDateID, LongDatetID  
   FROM tablename) p  
UNPIVOT  
   (value FOR key IN   
      (OwnerID, ShortList, DisplayList, QuickStart, ShortDateID, LongDatetID)  
)AS unpvt

你想要 apply :

select tt.[Key], tt.[Value]
from table t cross apply
     ( values ('OwnerID', OwnerID), 
              ('ShortList', ShortList), 
              ('DisplayList', DisplayList),
              ('QuickStart ', QuickStart),
              ('ShortDateID', ShortDateID),
              ('LongDatetID', LongDatetID)
     ) tt ([Key], [Value]);