473,432 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,432 software developers and data experts.

Selecting count of record by hour with zero values

28
How simple I can make query for MSSQL for selecting number of records step by 1 hour.. Including zero value..
I need return liek this..


2010/06/24 01:00 ; 2
2010/06/24 02:00 ; 0
2010/06/24 03:00 ; 10
2010/06/24 04:00 ; 11


thanks for all replies
Jun 24 '10 #1
3 2130
mwasif
802 Expert 512MB
Moved to MSSQL forum.
Jun 24 '10 #2
gpl
152 100+
@BbEsy
This can be simple
I assume you know how to extract the hour from the time, so you need to make sure that you have a full list of the possible hours in a day, simply create a table called AllHours and give it a numeric column called EachHour and insert the numbers 0 to 23 into it.

Now your query should be against the AllHours table and left join against your data table on the hours value. The COUNT will now identify all those hours which failed to match against your data table and give a value of zero.
Jun 28 '10 #3
You my try:

SELECT * FROM Table1 WHERE DATEPART(nn, ColDate) = 0

It should select only records where minutes = 0 - only hours
Jun 29 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chris | last post by:
I have the following table structure. group1 group2 group1_result group2_result 'One' 'Two' 3 2 'One' 'Two' 3 1 'One' 'Two' 2 5 'One' ...
6
by: Larry | last post by:
I have a stored procedure (below), that is suppose to get a Reg Number from a table, (Reg_Number), in such a way that every time the stored procedure is called, it will get a different reg number,...
8
by: Michael | last post by:
I have this script that works the way I want except for one thing... Once it hits zero it starts to count up and looks like this: -1:0-1:0-1:0-18 with the last number counting up. Can anyone...
4
by: David Peach | last post by:
Hello, hope somebody here can help me... I have a query that lists defects recorded in a user defined date range. That query is then used as the source for a Cross Tab query that cross-tabs count...
5
by: Randy Harris | last post by:
How can I report an average of non zero values? If the values are: 5, 0, 6, 0, 4 I would like the result 5 (15 / 3), not 3 (15 / 5) Thanks for any help...
2
by: jerome g | last post by:
Hi, I'm trying to use a (simple) form to create a new record, with all values being default values coming from a previous form. My problem is that I can save that new record only if I change one...
8
by: cppquester | last post by:
I am forced to work with a char* buf; I allocate memory and then construct some data types in buf (several different at different locations of buf kind of struct alike) Sometimes all data...
5
by: kwartz | last post by:
Can somebody please help me with a select statement for selecting duplicate records with one different field . I have 3 tables: A, B and C A has 2 fields I ---- primary key m B
4
by: techno58 | last post by:
In my form i want to be able to fill all my controls with a particular record by selecting that record from my datagridview.If i select a particular record after clicking on it all my controls like...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.