I have the following string to make it as expected.
Given String:
DECLARE @String VARCHAR(MAX) = '[ColumnA],[ColumnB],[ColumnC]'
/*Will be any numbers of columns*/
Expected String:
SUM([ColumnA]) AS [ColumnA],SUM([ColumnB]) AS [ColumnA],SUM([ColumnC]) AS [ColumnA]
My TRY:
SELECT 'SUM('+ REPLACE(@String,',','),SUM(') + ')'
I am just able to get:
SUM([ColumnA]),SUM([ColumnB]),SUM([ColumnC])
Got stuck to assign the alias infront of each sum.