I have customers that can belong to many groups at the same time. I need to create super-groups out of the distinct groups, in alphabetical order.
Cust_ID|Group
1 |Group 4
1 |Group 6
1 |Group 6
1 |Group 6
1 |Group 5
2 |Group 3
2 |Group 1
2 |Group 3
Desired outcome is
Cust_ID|Supergroup
1 |Group 4, Group 5, Group 6
2 |Group 1, Group 3
What I have tried
STRING_AGG STRING_AGG - not available in my SQL server version (I'm using 2016)
FOR XML PATH It's a bit hacky, but I've managed to get concatenation of all records in one field.
Select SUBSTRING( ( SELECT top 15 PolicyOwner1_CISKey, ',' + clientGroup AS 'data()' FROM IND_IN_SCOPE FOR XML PATH('') ), 2 , 9999) As Groups
PIVOT From my reading, it only seems to handle numerics, it's strings I'm needing to be aggregated.