Grouping results and combining duplicates as array I'm trying to write a query that gets all the records grouped by code and the rows that are duplicated are aggregated into an array.
+----------+---------+
| code     | name    |
+----------+---------+
| a        | Mike    |
| b        | Jones   |
| b        | Who     |
+----------+---------+

expected result:
+----------+----------------+
| code     | name           |
+----------+----------------+
| a        | Mike           |
| b        | [Jones, Who]   |
+----------+----------------+
I believe SQLServer 2017 introduced STRING_AGG:
select code, string_agg(name, '') as data
from T
group by code