I'm trying to concatenate column values when grouping in Microsoft Access using this code but keep getting a syntax error on the SELECT function inside STUFF.
Start with this table t1
fname | lname | Program | Site | Salary
------+-------+---------+------+-------
John | Smith | a | 1 | 10
John | Smith | a | 1 | 12
John | Smith | b | 3 | 15
Grace | Jones | b | 3 | 15
Grace | Jones | b | 3 | 15
Bob | Green | a | 7 | 10
and get this
fname | lname | Program | Site | Salary
------+-------+---------+------+-------
John | Smith | a | 1 | 10, 12
John | Smith | b | 3 | 15
Grace | Jones | b | 3 | 15
Bob | Green | a | 7 | 10
Here is the code I've been trying.
SELECT fname, lname, Program, Site,
STUFF((SELECT DISTINCT ',' + Salary
FROM t1
FOR XML PATH('')),1,1,'') AS Salaries
FROM t1
GROUP BY fname,lname,Program,Site;