0
來,我在下面的格式從SQL表中獲取數據:如何使用旋轉時,列標題是從數據庫
DisplayName PropertySystemName PropertyDefaultName PropertyValue
S1 P1 Property 1 Value 1
S1 P2 Property 2 Value 2
S1 P3 Property 3 Value 3
S1 P4 Property 4 Value 4
S1 P5 Property 5 Value 5
S1 P6 Property 6 Value 6
S1 P7 Property 7 Value 7
S1 P8 Property 8 Value 8
S1 P9 Property 9 Value 9
S1 P10 Property 10 Value 10
這是所需的輸出:
DisplayName Property 1 Property 2 Property 3
S1 Value 1 Value 2 Value 3
這是查詢我有,但它不會產生所需的輸出。
Select me.DisplayName,
Min(Case PropertySystemName When 'P1' Then PropertyValue End) PropertyDefaultName,
Min(Case PropertySystemName When 'P2' Then PropertyValue End) PropertyDefaultName,
Min(Case PropertySystemName When 'P3' Then PropertyValue End) PropertyDefaultName
FROM vManagedEntity me
這是上述查詢的輸出:
DisplayName PropertyDefaultName PropertyDefaultName PropertyDefaultName
S1 Value 1 Value 2 Value 3
如何修改查詢以產生所需的輸出沒有硬編碼列標題,因爲它已經存在於表中。
的[獲取行作爲可能重複COLUMNS(SQL Server動態PIVOT查詢)](http://stackoverflow.com/questions/12074939/get-rows-as-columns-sql-server-dynamic-pivot-query) – RichardTheKiwi