1
Supossing我們n
列與m
行動態SQL樞軸由列的SQL Server
table 1:
someName1 someName2 someName3 ... someNameN
----------------------------------------------
12.5 12.34 56.6 ... 33.2
1.2323 12.5 57.2 ... 123.1
2.789 45.2 766.1 ... 56.2
45.23 34.3 7.4 ... 33.4
52.1 4.3 89.8 ... 67.3
如何使用動態SQL一般
輸出(A table with n rows
,具有自動遞增ID,列名做表1和的總和列等):
ID Column Result
--------------------------------
1 someName1 SUM(someName1)=12.5+1.2323+2.789+45.23+52.1
2 someName2 SUM(someName2)=12.34+12.5+45.2+34.3+4.3
3 someName3 SUM(someName3)=56.6+57.2+766.1+7.4+89.8
... ...
... ...
N someNameN SUM(someName3)=33.2+123.1+56.2+33.4+67.3
凡SUM(columnName)
是的所有值相加的值如何做到這一點對任何大小的任何表,其中n
可能50
,換句話說一個table with 50 columns
?