Query to show Change Roles in change requests

Query to show Change Roles in change requests

MSSQL:

SELECT "chdt"."CHANGEID" AS "Change ID", "chdt"."TITLE" AS "Title", LONGTODATE("chdt"."CREATEDTIME") AS "Created Time", LONGTODATE("chdt"."SCHEDULEDSTARTTIME") AS "Scheduled Start Time", LONGTODATE("chdt"."SCHEDULEDENDTIME") AS "Scheduled End", "ownaaa"."FIRST_NAME" AS "Change Owner", 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, '') '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=9 FOR XML PATH ('')), 1, 1, '') 'Reviewer', 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, '') 'Line Manager',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=5 FOR XML PATH ('')), 1, 1, '') 'Change Approver', "priodef1"."PRIORITYNAME" AS "Priority", "ctdef"."NAME" AS "Change Type", "approvaldef"."STATUSNAME" AS "Approval Status", "catadef"."CATEGORYNAME" AS "Category", "sdo"."NAME" AS "Site", "qd"."QUEUENAME" AS "Group", "stageDef"."DISPLAYNAME" AS "Stage", "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 "PriorityDefinition" "priodef1" ON "chdt"."PRIORITYID"="priodef1"."PRIORITYID" LEFT JOIN "ChangeTypeDefinition" "ctdef" ON "chdt"."CHANGETYPEID"="ctdef"."CHANGETYPEID" LEFT JOIN "ApprovalStatusDefinition" "approvaldef" ON "chdt"."APPR_STATUSID"="approvaldef"."STATUSID" LEFT JOIN "CategoryDefinition" "catadef" ON "chdt"."CATEGORYID"="catadef"."CATEGORYID" LEFT JOIN "SiteDefinition" "siteDef" ON "chdt"."SITEID"="siteDef"."SITEID" LEFT JOIN "SDOrganization" "sdo" ON "siteDef"."SITEID"="sdo"."ORG_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"

PGSQL:

SELECT  cdt.changeid "Change Request ID", orgaaa.FIRST_NAME AS "Change Requester", ownaaa.FIRST_NAME AS "Change Owner", cmDef.FIRST_NAME AS "Change Manager", manager.name "Line Manager", implementer.name "Change Implementer", Reviewer.name "Change Reviewer", Approver.name "Change Approver" FROM ChangeDetails cdt   LEFT JOIN (SELECT role.changeid, array_to_string(array_agg(us.first_name),',') AS name FROM changeroleusermapping ROLE LEFT JOIN aaauser us ON ROLE.userid=us.user_id WHERE ROLE.roleid=8 GROUP BY ROLE.changeid)implementer ON cdt.changeid=implementer.changeid LEFT JOIN (SELECT role.changeid, array_to_string(array_agg(us.first_name),',') AS name FROM changeroleusermapping ROLE LEFT JOIN aaauser us ON ROLE.userid=us.user_id WHERE ROLE.roleid=9 GROUP BY ROLE.changeid)Reviewer ON cdt.changeid=reviewer.changeid LEFT JOIN (SELECT role.changeid, array_to_string(array_agg(us.first_name),',') AS name FROM changeroleusermapping ROLE LEFT JOIN aaauser us ON ROLE.userid=us.user_id WHERE ROLE.roleid=5 GROUP BY ROLE.changeid)Approver ON cdt.changeid=Approver.changeid LEFT JOIN (SELECT role.changeid, array_to_string(array_agg(us.first_name),',') AS name FROM changeroleusermapping ROLE LEFT JOIN aaauser us ON ROLE.userid=us.user_id WHERE ROLE.roleid=7 GROUP BY ROLE.changeid)manager ON cdt.changeid=manager.changeid LEFT JOIN SDUser orgsd ON cdt.INITIATORID=orgsd.USERID LEFT JOIN AaaUser orgaaa ON orgsd.USERID=orgaaa.USER_ID LEFT JOIN SDUser ownsd ON cdt.TECHNICIANID=ownsd.USERID LEFT JOIN AaaUser ownaaa ON ownsd.USERID=ownaaa.USER_ID LEFT JOIN AaaUser cmDef ON cdt.CHANGEMANAGERID=cmDef.USER_ID
          • Related Articles

          • Change Submission and Planning stage details

            PGSQL: SELECT  cdt.changeid "Change Request ID", orgaaa.FIRST_NAME AS "Change Requester", ownaaa.FIRST_NAME AS "Change Owner", cmDef.FIRST_NAME AS "Change Manager", manager.name "Line Manager", implementer.name "Change Implementer", Reviewer.name ...
          • Query to show Approved tickets per Approver

            PGSQL & MSSQL: SELECT wo.WORKORDERID "Request ID", wo.TITLE "Subject", std.STATUSNAME "Request Status", ti.FIRST_NAME "Technician", longtodate(wo.CREATEDTIME) "Created Time", ApprovalDetails.EMAIL "Approver Email", asd.stagename "Stage", ...
          • Query report to show Open requests without open tasks

            PGSQL & MSSQL: SELECT wo.WORKORDERID AS "Ticket Number", pd.PRIORITYNAME AS "Priority", cd.CATEGORYNAME AS "Category", ti.FIRST_NAME AS "Technician", aau.FIRST_NAME AS "Requester", wotodesc.FULLDESCRIPTION AS "Description", std.STATUSNAME AS "Request ...
          • Instruction to Change Worklog owner under All Request, worklog owner From Tech A to Tech B

            Scenario      Worklogs assigned to Duplicate user / Incorrect user need to change all worklogs under request  to actual Technician.  Step 1 : Navigate to Report - > New Query Report and execute the below query.  Select workorder.workorderid ...
          • Query to show users of Organization Roles for each account

            PGSQL & MSSQL: select ad.org_name "Account Name", org.orgrolename "ORG Role Name", aau.first_name "User" from orgroles org left join roletousermapping rtu ON org.orgroleid=rtu.roleid LEFT JOIN roletouseraccountmapping rum ON rtu.rumid=rum.rumid LEFT ...