Query to show all request along with a column to show survey completed or not. (MSSQL & PGSQL)

Query to show all request along with a column to show survey completed or not. (MSSQL & PGSQL)

Tested in builds PGSQL (14300) or MSSQL (14306)
Please go to Reports > New Query Reports and execute the below query (MS-SQL & PGSQL):

SELECT wo.WORKORDERID AS "Request ID",
       max(wo.TITLE) AS "Request Title",
       max(aau.FIRST_NAME) AS "Requester",
       max(ti.FIRST_NAME) AS "Technician",
       longtodate(max(wo.completedtime)) AS "Completed Time",
   CASE WHEN max(srm.Responsetime) IS NOT NULL THEN 'TRUE' ELSE 'FALSE' END "Survey Attended ?",
       longtodate(max(srm.Responsetime)) AS "Survey responded Time",
       max(srm.result) "Survey %" FROM WorkOrder wo
LEFT JOIN SurveyResponseRequestMapping srrm ON srrm.WORKORDERID=wo.WORKORDERID  
LEFT JOIN Survey_Response_Main srm ON srrm.RESPONSEID=srm.RESPONSEID
LEFT JOIN Survey_Response_Answer sra ON srm.RESPONSEID=sra.RESPONSEID
LEFT JOIN Survey_Question sq ON sra.QUESID=sq.QUESID
LEFT JOIN SDUser sdu ON wo.REQUESTERID=sdu.USERID
LEFT JOIN AaaUser aau ON sdu.USERID=aau.USER_ID
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
where wo. completedtime >= <from_yesterday> AND wo. completedtime <= <to_yesterday>
GROUP BY wo.WORKORDERID

How to compare date column with auto filled date templates?
  1. Here is the example for getting this week data - CREATEDTIME >= <from_thisweek> AND CREATEDTIME <= <to_thisweek>
    • <from_thisweek> - Starting date of this week
    • <to_thisweek> - Ending date of this week
  2. Available Date Templates
    • Today - <from_today> - <to_today>
    • This week - <from_thisweek> - <to_thisweek>
    • Last week - <from_lastweek> - <to_lastweek>
    • This month - <from_thismonth> - <to_thismonth>
    • Last month - <from_lastmonth> - <to_lastmonth>
    • This quarter - <from_thisquarter> - <to_thisquarter>
    • Last quarter - <from_lastquarter> - <to_lastquarter>
    • Yesterday - <from_yesterday> - <to_yesterday>

                  New to ADSelfService Plus?