Wednesday, December 16, 2020

Convert Rows to 1 column - STRING_AGG - with order by




 select Col1, Col2, Col3, STRING_AGG( Col4,',')  WITHIN GROUP (ORDER BY Col4) as AggregatedColumn  from MyTable

group by Col1,Col2,Col3


No comments:

Post a Comment

Recently Executed queries

 SELECT     txt.TEXT AS [SQL Statement],     qs.EXECUTION_COUNT [No. Times Executed],     qs.LAST_EXECUTION_TIME AS [Last Time Executed],   ...