Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Counts Per Hour

$
0
0

I have the query below and the results below that.  Would someone tell me how I would be able to run this for multiple days?  If I change the date in the query it will just add to the specific time periods.  How do I tweak it to do it daily for say a specific month and the corresponding counts per hour.

Example

2013/08/01 – 12am – 2000

2013/08/01 – 1am – 500

USE winpayment
BEGIN
SET NOCOUNT ON
DECLARE @BeginDate DATETIME
DECLARE @EndDate DATETIME
SET @BeginDate = '2013-06-03 00:00:00.0' --< ENTER the BEGIN date.
SET @EndDate = '2013-06-04 00:00:00.0' --< ENTER the END date.
BEGIN
-- Use the following select to get the counts by by hour for the specified date
SELECT CAST(@BeginDate AS CHAR(20)) AS 'Begin Date', CAST(@EndDate AS CHAR(20)) AS 'End Date'
PRINT 'Point Messsage by HOUR'
SELECT      
CONVERT(CHAR(5), DATEPART(hh, creation_date), 10) 'Hour',
COUNT (*) 'NBR Trans'
FROM
point_message WITH (NOLOCK)
WHERE
creation_date BETWEEN @BeginDate AND @EndDate
GROUP BY DATEPART(hh, creation_date)
END
SET NOCOUNT OFF
END

Results:

Begin Date           End Date
-------------------- --------------------
Jun  3 2013 12:00AM  Jun  4 2013 12:00AM

Point Messsage by HOUR
Hour  NBR Trans
----- -----------
0     8912
1     38698
2     5949
3     7614
4     15912
5     30419
6     48251
7     58234
8     49928
9     43058
10    41517
11    45962
12    52837
13    44726
14    41473
15    43749
16    45040
17    45291
18    37079
19    30890
20    27975
21    23877
22    18491
23    13579


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>