How can create a query to grouping fields ?
Like STUFF or STRING_AGG functions
SELECT id,
STUFF (
(SELECT
',' +name
FROM temp1
FOR XML PATH('')), 1, 1, ''
) as Name
FROM temp1 GROUP BY id
or
SELECT id,
STRING_AGG (name , ',') AS Name
FROM temp1 GROUP BY id
Output:
-----------------------------------
| id | Name |
|---------------------------------|
| 1 | aaa,bbb,ccc,ddd,eee |
-----------------------------------