Get Hourly Created records count for a day from a SQL Table

SELECT STUFF(RIGHT(CONVERT(VARCHAR,Createddate,0),7),3,3,' ') + ' - ' +
STUFF(RIGHT(CONVERT(VARCHAR,DATEADD(HOUR,1,Createddate),0),7),3,3,' ') AS HOUR, COUNT(*) AS COUNT
FROM tableName
WHERE Createddate BETWEEN CONVERT(DATETIME,FLOOR(CONVERT(FLOAT,GETDATE()))) AND CONVERT(DATETIME,FLOOR(CONVERT(FLOAT,GETDATE())) + 1)
GROUP BY STUFF(RIGHT(CONVERT(VARCHAR,Createddate,0),7),3,3,' ') + ' - ' +
STUFF(RIGHT(CONVERT(VARCHAR,DATEADD(HOUR,1,Createddate),0),7),3,3,' ')
ORDER BY 1

Comments

Popular posts from this blog

How to Convert Word Document to PDF using C#

Sql query to get counts by quarterly and half yearly

How to upload File to Secured FTP ( SFTP ) in C#