Version : 14300
DB : MSSQL
OUTPUT:
Query :
select case when
(DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00'))>0 AND DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00')) <= 3) then '0:00 to 3:00 hrs'
when
(DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00'))>3 AND DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00')) <= 6) then '3:00 to 6:00 hrs'
when
(DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00'))>6 AND DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00')) <= 9 ) then '6:00 to 9:00 hrs'
when
(DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00'))>9 AND DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00')) <= 12) then '9:00 to 12:00 hrs'
when
(DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00'))>12 AND DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00')) <= 15) then '12:00 to 15:00 hrs'
when
(DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00'))>15 AND DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00')) <= 18 ) then '15:00 to 18:00 hrs'
when
(DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00'))>18 AND DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00')) <= 21 ) then '18:00 to 21:00 hrs'
when
(DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00'))>21 AND DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00')) <= 24 ) then '21:00 to 24:00 hrs' else null end "Hours", count(wo.workorderid) "Count of Request" from workorder wo
group by DATEPART(hh,dateadd(s,datediff(s,GETUTCDATE() ,getdate()) + (wo.CREATEDTIME/1000),'1970-01-01 00:00:00'))
order by 1