I need a report showing :
“Column1Name”, sum(column1)
“Column2Name”, sum(Column2)
……………………….
“Column600Name”, sum(Column600)
Where Column 1, …. Column_600 are all numeric
So in total there are 600 columns and the table is 60 GB.
I focus also on performance.
1.below works but very poor:
Select ‘Column1’ ColumnName , sum(Column1) as SumColumn from TableName union all
Select ‘Column2’ ColumnName , sum(Column2) as SumColumn from TableName union all
………………………….
Select ‘Column_N’ ColumnName , sum(Column_N) as SumColumn from TableName
2.Another idea that I consider is
Select sum(Column1) as SumColumn1,
sum(Column2) as SumColumn2,
…….
sum(Column600) as SumColumn600
from TableName
and then transposing (pivot) the columns to rows (the columnName_N can be parsed from the SumColumn_N column name)
Wondering if any better solution that 1. Or 2.
Thank you very much.