with a as ( select 'a' [a],'1' [b] union all select 'a' [a],'2' [b] union all select 'a' [a],'3' [b] union all select 'a' [a],'4' [b] union all select 'a' [a],'5' [b] union all select 'b' [a],'1' [b] union all select 'b' [a],'3' [b] union all select 'b' [a],'4' [b] union all select 'b' [a],'9' [b] ) select a,STRING_AGG(B,';') from a GROUP BY A
|