Hi @Michael "Captain Jack" Breen
According to the screenshot you post, you need to modify the subquery of STUFF function:
SELECT DISTINCT
sta.lastName as 'Last Name *',
sta.firstName as 'First Name *',
con.email as 'Email Address *',
sta.staffNumber as 'Staff ID *',
'Y' as 'Is Active *',
'"' + STUFF((SELECT DISTINCT', ' + C.[value] /*The placement of the '"' puts double-quotes around the entire string in the column*/
FROM customSchool C JOIN staffMember S on S.schoolID = C.schoolID and S.StuffNumber=sta.StuffNumber
WHERE C.attributeID = 618 FOR XML PATH('')),1,2,'') + '"' [Building ID{s}*],
'Y' as 'Certificate Holder *'
from staffMember sta
JOIN contact con ON con.personID = sta.personID
JOIN customSchool css on css.schoolID = sta.schoolID
where sta.endDate IS NULL
AND sta.staffNumber is NOT NULL
AND con.email is NOT NULL
AND css.attributeID = 618
order by sta.lastName
If it still doesn't work, please provide your table structure (CREATE TABLE …) and some sample data(INSERT INTO …). So that we’ll get a right direction and make some test.
Best regards,
LiHong