Query to show Approved tickets per Approver (MSSQL & PGSQL)

Query to show Approved tickets per Approver (MSSQL & PGSQL)

Tested in Build PGSQL (14300) or MSSQL (14306)

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",
ApprovalStatusDefinition.STATUSNAME "Approval Status",
LONGTODATE(ApprovalStage.SENT_DATE) "Approval Sent date",
LONGTODATE(ApprovalDetails.ACTION_DATE) "Approved Date" FROM WorkOrder wo
LEFT JOIN SDUser sdu ON wo.REQUESTERID=sdu.USERID
LEFT JOIN AaaUser aau ON sdu.USERID=aau.USER_ID
LEFT JOIN DepartmentDefinition dpt ON wo.DEPTID=dpt.DEPTID
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN SDUser td ON wos.OWNERID=td.USERID
LEFT JOIN AaaUser ti ON td.USERID=ti.USER_ID
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID
JOIN ApprovalStageMapping ON wo.WORKORDERID=ApprovalStageMapping.WORKORDERID
LEFT JOIN ApprovalDetails ON ApprovalStageMapping.APPROVAL_STAGEID=ApprovalDetails.APPROVAL_STAGEID
LEFT JOIN ApprovalStage ON ApprovalDetails.APPROVAL_STAGEID=ApprovalStage.APPROVAL_STAGEID
LEFT JOIN approvalstatusdefinition ON ApprovalDetails.STATUSID=ApprovalStatusDefinition.STATUSID
LEFT JOIN approvalstagedefinition asd ON asd.STAGEID=ApprovalDetails.STAGEID
LEFT JOIN aaauser createduser on createduser.user_id=wo.createdbyid
left join workorder_queue ON workorder_queue.workorderid=wo.workorderid 
left join queuedefinition ON workorder_queue.queueid=queuedefinition.queueid
LEFT JOIN ServiceCatalog_Fields scf on scf.workorderid=wo.workorderid
LEFT JOIN requesttemplate_list reqlist on reqlist.templateid=wo.templateid
WHERE ApprovalStatusDefinition.STATUSNAME='Approved' AND ApprovalDetails.EMAIL IN('abc@zoho.com','hari@manageengine.com') AND wo.CREATEDTIME >= DATETOLONG('2020-04-01 07:00:00')  AND wo.CREATEDTIME <= DATETOLONG('2020-04-30 23:59:59')

Note: Approver email ID and Date filter needs to be modified as per the need.

                  New to ADSelfService Plus?