No sql 2017 você pode usar a função STRING_AGG: SELECT STRING_AGG(T.val, ',') AS val , T.grp FROM @tbl AS T GROUP BY T.grp