Query to find replies sent to a requester excluding the system notifications (MSSQL)

Query to find replies sent to a requester excluding the system notifications (MSSQL)

Tested in build MSSQL (14306)


Query

select wo.workorderid as "Ticket ID",
convert(date, DATEADD(s,(wo.CREATEDTIME)/1000,'01-01-1970')) AS "Creatd Date",
format (convert(time, DATEADD(s,(wo.CREATEDTIME)/1000,'01-01-1970')), 'hh') + ':' +
format (convert(time, DATEADD(s,(wo.CREATEDTIME)/1000,'01-01-1970')), 'mm') + ':' +
format (convert(time, DATEADD(s,(wo.CREATEDTIME)/1000,'01-01-1970')), 'mm') AS "Create Time",
n.NOTIFICATIONID,
convert(date, DATEADD(s,(n.NOTIFICATIONDATE)/1000,'01-01-1970')) AS "Reply Date",
format (convert(time, DATEADD(s,(n.NOTIFICATIONDATE)/1000,'01-01-1970')), 'hh') + ':' +
format (convert(time, DATEADD(s,(n.NOTIFICATIONDATE)/1000,'01-01-1970')), 'mm') + ':' +
format (convert(time, DATEADD(s,(n.NOTIFICATIONDATE)/1000,'01-01-1970')), 'mm') AS "Reply Time",
n.NOTIFICATIONTITLE as "title",
aau.FIRST_NAME as "sender",
au.FIRST_NAME as "Recipient",
nr.RECIPIENT_EMAIL "Email",
au.USER_ID from notify_workorder nw
left join Notification n on n.NOTIFICATIONID = nw.NOTIFICATIONID
LEFT JOIN notification_recipients nr ON nr.NOTIFICATIONID=n.NOTIFICATIONID
left join WorkOrder wo on wo.WORKORDERID = nw.WORKORDERID
LEFT JOIN SiteDefinition siteDef ON wo.SITEID=siteDef.SITEID
LEFT JOIN SDOrganization sdo ON siteDef.SITEID=sdo.ORG_ID
LEFT JOIN accountsitemapping asm on asm.siteid=sitedef.siteid
LEFT JOIN accountdefinition adef on adef.org_id=asm.accountid
LEFT JOIN WorkOrder_Fields wof ON wof.workorderid=wo.workorderid
LEFT JOIN AaaUser aau ON n.SENDERID=aau.USER_ID
LEFT JOIN AaaUser au ON n.RECIPIENTID=au.USER_ID
where nr.RECIPIENT_EMAIL='req4@abc.com'
and Notificationtype = 'REQREPLY'
and n.SENDERID != '1'
and (wo.createdtime/1000between datediff(s,'1970-01-01 00:00','2022-07-01 00:00') and datediff(s,'1970-01-01 00:00','2022-12-31 23:59')) 

Notes 
  1. You can toggle n.SENDERID != '1' value to 1 or 0. 1=response, 0=automated notification. You can remove and n.SENDERID != '1' to get both the data at once. 
  2. You can replace the dates to your own time frame. 



                  New to ADSelfService Plus?