TSQL: PIVOT table with hours
Transact-SQL
1. Table containg names and time
Columns: Name, CreatedOn
Table: RegisterTime
2. Query
SELECT * FROM
(SELECT Name, DATEPART(HOUR, CreatedOn) AS RcpHour FROM RegisterTime) sourceTable PIVOT (COUNT(RcpHour) FOR RcpHour IN ( [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23])) as pvtTable