Group time by hour from datetime field in SQL Server

  SELECT CAST(ENTRY_DATE as date) AS ForDate,
       DATEPART(hour,ENTRY_DATE) AS OnHour,
       COUNT(*) AS Totals
FROM [BATB].[dbo].[CONSUMER_INFO]
GROUP BY CAST(ENTRY_DATE as date),
       DATEPART(hour,ENTRY_DATE)
       Having CAST(ENTRY_DATE as date)=’2014-02-12′
       Order by DATEPART(hour,ENTRY_DATE) ASC
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s