Query to show number of tickets created per template with their status (MSSQL & PGSQL)

Query to show number of tickets created per template with their status (MSSQL & PGSQL)

Tested in build PGSQL (14300) and MSSQL (14306)


SELECT reqtl.TEMPLATENAME "Request Template", 
 count(wo.WORKORDERID) "Request Count",
count(case when std.ispending='0' THEN 1 ELSE NULL END) "Completed",
count(case when std.ispending='1' THEN 1 ELSE NULL END) "Pending"
 FROM WorkOrder wo
LEFT JOIN RequestTemplate_list reqtl ON wo.TEMPLATEID=reqtl.TEMPLATEID 
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID 
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID
where reqtl.TEMPLATENAME='New site planning'
group by  reqtl.TEMPLATENAME,reqtl.templateid


Note: Requeste template name is highlighted in this query, can be modified if needed.

                  New to ADSelfService Plus?