SELECT sdo.name "Site Name", qd.QUEUENAME "Support group",
site.isdeleted "Site Active", qd.isdeleted "Group Active",
qd.QUEUEDESCRIPTION "Description",
STUFF(
(SELECT ',' + au.first_name
FROM queue_technician qt
LEFT JOIN sduser sd ON qt.technicianid=sd.userid
LEFT JOIN aaauser au ON sd.userid=au.user_id
WHERE qt.queueid=qd.queueid
FOR XML PATH('')),1,1,'') AS "Interested Technicians",
STUFF(
(SELECT ',' + au.first_name
FROM queueescalation qe
LEFT JOIN escalateton esc ON qe.escalatetoid=esc.escalatetoid
LEFT JOIN sduser sd ON esc.userid=sd.userid
LEFT JOIN aaauser au ON sd.userid=au.user_id
WHERE qe.category='NOTIFY_REQ_ADD_IN_QUEUE'
AND qe.queueid=qd.queueid
FOR XML PATH('')),1,1,'') AS "Notify when new request is added",
STUFF(
(SELECT ',' + au.first_name
FROM queueescalation qe
LEFT JOIN escalateton esc ON qe.escalatetoid=esc.escalatetoid
LEFT JOIN sduser sd ON esc.userid=sd.userid
LEFT JOIN aaauser au ON sd.userid=au.user_id
WHERE qe.category='NOTIFY_UNPICK_REQ_IN_QUEUE'
AND qe.queueid=qd.queueid
FOR XML PATH('')),1,1,'') AS "Notify when request is left unpicked",
STUFF(
(SELECT ',' + au.first_name
FROM queueescalation qe
LEFT JOIN escalateton esc ON qe.escalatetoid=esc.escalatetoid
LEFT JOIN sduser sd ON esc.userid=sd.userid
LEFT JOIN aaauser au ON sd.userid=au.user_id
WHERE qe.category='NOTIFY_REQ_EDIT_IN_QUEUE'
AND qe.queueid=qd.queueid
FOR XML PATH('')),1,1,'') AS "Notify when request is updated",
STUFF(
(SELECT ',' + qe.email
FROM queue_email qe
WHERE qe.queueid=qd.queueid
FOR XML PATH('')),1,1,'') AS "Group E-Mail",
qd.sendername "Sender's Name",
qd.replyaddress "Sender's e-mail"
FROM QueueDefinition qd
LEFT JOIN SiteDefinition site ON qd.siteid=site.siteid
LEFT JOIN SDOrganization sdo ON sdo.org_id=site.siteid
order by 1,2