Tested in build MSSQL (14306)
SELECT QUEUEDEFINITION.QUEUENAME,COUNT(WORKORDER.WORKORDERID) 'Total Pending Count',
COUNT(CASE WHEN DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) <= 2 THEN 1 ELSE NULL END) '0 - 2 hours',
COUNT(CASE when DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) <= 5 and DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) > 2 THEN 1 ELSE NULL END) '2 - 5 hours',
COUNT(CASE when DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) <= 10 and DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) > 5 THEN 1 ELSE NULL END) '5 - 10 hours',
COUNT(CASE when DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) <= 15 and DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) > 10 THEN 1 ELSE NULL END) '10 - 15 hours',
COUNT(CASE when DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) <= 30 and DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) > 15 THEN 1 ELSE NULL END) '15 - 30 hours',
COUNT(CASE when DATEDIFF(y, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +((WORKORDER.createdtime)/1000),'1970-01-01 00:00:00'),GETDATE()) > 30 THEN 1 ELSE NULL END) 'More than 30 hours' FROM WORKORDER
INNER JOIN WORKORDERSTATES on WORKORDERSTATES.WORKORDERID = WORKORDER.WORKORDERID LEFT JOIN STATUSDEFINITION on STATUSDEFINITION.STATUSID = WORKORDERSTATES.STATUSID LEFT JOIN WORKORDER_QUEUE ON WORKORDER.WORKORDERID = WORKORDER_QUEUE.WORKORDERID LEFT JOIN QUEUEDEFINITION ON WORKORDER_QUEUE.QUEUEID=QUEUEDEFINITION.QUEUEID WHERE WORKORDERSTATES.STATUSID IN ( Select STATUSID from StatusDefinition where ISPENDING=1) GROUP BY QUEUEDEFINITION.QUEUENAME
ORDER BY QUEUEDEFINITION.QUEUENAME
You can replace the highlighted y with the below interval parameters.
Parameter | Description |
---|
interval | Required. The part to return. Can be one of the following values:- year, yyyy, yy = Year
- quarter, qq, q = Quarter
- month, mm, m = month
- dayofyear = Day of the year
- day, dy, y = Day
- week, ww, wk = Week
- weekday, dw, w = Weekday
- hour, hh = hour
- minute, mi, n = Minute
- second, ss, s = Second
- millisecond, ms = Millisecond
|