SELECT chdt.CHANGEID AS "Change ID",
chdt.TITLE AS "Title",
orgaaa.FIRST_NAME AS "Change Requester",
qd.QUEUENAME AS "Group",
ownaaa.FIRST_NAME AS "Change Owner",
catadef.CATEGORYNAME AS "Category",
priodef1.PRIORITYNAME AS "Priority",
longtodate(chdt.CREATEDTIME) AS "Created Time",
longtodate(chdt.COMPLETEDTIME) AS "Completed Time",
stageDef.DISPLAYNAME AS "Stage",
statusDef.STATUSDISPLAYNAME AS "Status",
approvaldef.STATUSNAME AS "Approval Status",
appr.FIRST_NAME as "Approver",
al.name as "Approval level name",
longtodate(ad.action_date) as "Approval action taken on" ,
ad.COMMENTS as "Approval Comments",
appr_status_defn.statusname as "Approval status"
from changedetails chdt LEFT JOIN AaaUser orgaaa ON chdt.INITIATORID=orgaaa.USER_ID LEFT JOIN AaaUser ownaaa ON chdt.TECHNICIANID=ownaaa.USER_ID
LEFT JOIN PriorityDefinition priodef1 ON chdt.PRIORITYID=priodef1.PRIORITYID
LEFT JOIN ApprovalStatusDefinition approvaldef ON chdt.APPR_STATUSID=approvaldef.STATUSID
LEFT JOIN CategoryDefinition catadef ON chdt.CATEGORYID=catadef.CATEGORYID
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
LEFT JOIN AaaUser cmDef ON chdt.CHANGEMANAGERID=cmDef.USER_ID
LEFT JOIN Change_ApprovalLevel cal ON cal.ENTITYID = chdt.CHANGEID LEFT JOIN ApprovalLevel al ON al.ID = cal.LEVELID LEFT JOIN ApprovalDetails ad ON ad.APPROVAL_LEVEL_ID = al.ID LEFT JOIN AaaUser appr ON appr.USER_ID = ad.APPROVERID LEFT JOIN approvalStatusDefinition appr_status_defn on appr_status_defn.statusid = ad.statusid
order by 1