SELECT YEAR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) 'created time',
CASE
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=1 THEN '1. JAN'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=2 THEN '2. FEB'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=3 THEN '3. MAR'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=4 THEN '4. APR'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=5 THEN '5. MAY'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=6 THEN '6. JUN'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=7 THEN '7. JUL'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=8 THEN '8. AUG'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=9 THEN '9. SEP'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=10 THEN '10. OCT'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=11 THEN '11. NOV'
WHEN MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))=12 THEN '12. DEC'
ELSE NULL
END 'MONTH',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =0 THEN 1
ELSE NULL
END) '0-1',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =1 THEN 1
ELSE NULL
END) '1-2',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =2 THEN 1
ELSE NULL
END) '2-3',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =3 THEN 1
ELSE NULL
END) '3-4',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =4 THEN 1
ELSE NULL
END) '4-5',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =5 THEN 1
ELSE NULL
END) '5-6',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =6 THEN 1
ELSE NULL
END) '6-7',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =7 THEN 1
ELSE NULL
END) '7-8',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =8 THEN 1
ELSE NULL
END) '8-9',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =9 THEN 1
ELSE NULL
END) '9-10',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =10 THEN 1
ELSE NULL
END) '10-11',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =11 THEN 1
ELSE NULL
END) '11-12',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =12 THEN 1
ELSE NULL
END) '12-13',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =13 THEN 1
ELSE NULL
END) '13-14',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =14 THEN 1
ELSE NULL
END) '14-15',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =15 THEN 1
ELSE NULL
END) '15-16',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =16 THEN 1
ELSE NULL
END) '16-17',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =17 THEN 1
ELSE NULL
END) '17-18',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =18 THEN 1
ELSE NULL
END) '18-19',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =19 THEN 1
ELSE NULL
END) '19-20',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =20 THEN 1
ELSE NULL
END) '20-21',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =21 THEN 1
ELSE NULL
END) '21-22',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =22 THEN 1
ELSE NULL
END) '22-23',
COUNT(CASE
WHEN HOUR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')) =23 THEN 1
ELSE NULL
END) '23-0'
FROM workorder
GROUP BY MONTH(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00')),
YEAR(dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (CREATEDTIME/1000), '1970-01-01 00:00:00'))
ORDER BY 1,
2