I'm having a bit of trouble implementing the XML PATH method of concatenating multiple rows. So, given the following sql-table, temptable
user | userid | email | group
a usera [email protected] admin
a usera [email protected] test
a usera [email protected] edit
b userb [email protected] read
b userb [email protected] write
c userc [email protected] read
c userc [email protected] write
i receive with this code the following:
SELECT a.[user],
STUFF((SELECT ', ' + [group] [text()]
FROM [temptable]
WHERE [user] = a.[user]
for XML PATH (''),TYPE).
value('.','NVARCHAR(MAX)'),1,2,'') AS [group]
FROM [temptable] as a
GROUP BY a.[user]
result:
user | group
a admin,test,edit
b read,write
c read,write
but i need this
user | userid | email | group
a usera [email protected] admin,test,edit
b userb [email protected] read,write
c userc [email protected] read,write