SELECT
    p.person_id,
    p.employee_code,
    p.first_name,
    p.last_name,
    p.email,
    p.primary_telephone,
    p.address1,
    p.address2,
    p.city,
    p.country,
    p.state_province_region,
    p.zip_or_postal_code,
    p.is_blocked,
    cd.data_json AS customdata,
    membership = STUFF((
          SELECT DISTINCT ',' + ug.group_code
          FROM (SELECT
        p.person_id, ug.group_code
    FROM
        person p
    LEFT JOIN user_group_membership ugm ON p.person_id = ugm.member AND ugm.end_date IS NULL AND p.customer_id=:customerParam
    INNER JOIN
    usergroup ug ON assigned_group_id = ug.group_id AND ugm.end_date IS NULL) ug where ug.person_id=p.person_id
          FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')
FROM person p