0
我已經搜索了很多使用變量名作爲列名,但是我找不到任何東西。我有一個表,其中nameMaster列和xVariable,yVariable,zVariable底下。我知道我可以使用:mssql 2008 - 使用變量作爲列名稱
case nameMaster when 'xVariable' then total else 0 end AS xVariable
case nameMaster when 'yVariable' then total else 0 end AS yVariable
case nameMaster when 'zVariable' then total else 0 end AS zVariable
但是我喜歡在循環中做到這一點,而不是手動。
我的表是這樣的:
nameMaster | total
---------------------
xVariable | 10.000
yVariable | 20.000
zVariable | 30.000
我想顯示是這樣的:
xVariable | yVariable | zVariable
---------------------------------
10.000 20.000 30.000
在此先感謝..
非常感謝你的雪茄!這是我一直在尋找的。 – Ozland
另請參閱Roman Pekar的動態列解決方案http://stackoverflow.com/questions/13245364/ms-sql-server-pivot-table-with-subquery-in-column-clause – Ozland