SELECT "chdt"."CHANGEID" AS "Change ID", "chdt"."TITLE" AS "Title", LONGTODATE(chdt.CREATEDTIME) AS "Created Time", "ownaaa"."FIRST_NAME" AS "ChangeOwner", STUFF((SELECT ', '+ au.first_name + char(10) FROM changeroleusermapping crum
left join aaauser au on au.user_id=crum.userid
where chdt.changeid=crum.changeid and crum.roleid=7 FOR XML PATH ('')), 1, 1, '') 'Implementer', STUFF((SELECT ', '+ au.first_name + char(10) FROM changeroleusermapping crum
left join aaauser au on au.user_id=crum.userid
where chdt.changeid=crum.changeid and crum.roleid=8 FOR XML PATH ('')), 1, 1, '') 'Reviewer', "stageDef"."DISPLAYNAME" AS "Stage", CASE WHEN stageDef.DISPLAYNAME='Implementation' THEN STUFF((SELECT ', '+ au.first_name + char(10) FROM changeroleusermapping crum
left join aaauser au on au.user_id=crum.userid
where chdt.changeid=crum.changeid and crum.roleid=7 FOR XML PATH ('')), 1, 1, '') WHEN stageDef.DISPLAYNAME='Review' THEN STUFF((SELECT ', '+ au.first_name + char(10) FROM changeroleusermapping crum
left join aaauser au on au.user_id=crum.userid
where chdt.changeid=crum.changeid and crum.roleid=8 FOR XML PATH ('')), 1, 1, '') ELSE ownaaa.FIRST_NAME END AS "ACTION PENDINGBY", "statusDef"."STATUSDISPLAYNAME" AS "Status" FROM "ChangeDetails" "chdt" LEFT JOIN "SDUser" "ownsd" ON "chdt"."TECHNICIANID"="ownsd"."USERID" LEFT JOIN "AaaUser" "ownaaa" ON "ownsd"."USERID"="ownaaa"."USER_ID" LEFT JOIN "QueueDefinition" "qd" ON "chdt"."GROUPID"="qd"."QUEUEID" LEFT JOIN "Change_StageDefinition" "stageDef" ON "chdt"."WFSTAGEID"="stageDef"."WFSTAGEID" LEFT JOIN "Change_StatusDefinition" "statusDef" ON "chdt"."WFSTATUSID"="statusDef"."WFSTATUSID" INNER JOIN "AccountSiteMapping" "asm" ON "chdt"."SITEID"="asm"."SITEID" INNER JOIN "AccountDefinition" "ad" ON "asm"."ACCOUNTID"="ad"."ORG_ID" WHERE ( ( ( ( "statusDef"."STATUSDISPLAYNAME" COLLATE SQL_Latin1_General_CP1_CS_AS != N'Canceled' ) AND ( "statusDef"."STATUSDISPLAYNAME" COLLATE SQL_Latin1_General_CP1_CS_AS != N'Completed' ) AND ( "statusDef"."STATUSDISPLAYNAME" COLLATE SQL_Latin1_General_CP1_CS_AS != N'Approval Pending' ) ) ) )