Trying to return zeroes in between statement

A

alphamisanthrope

Please help, y'all.

Here's my statement:
SELECT tblTime.Hour, Count(*) AS HowMany
FROM tblStay, tblTime
WHERE tblTime.Hour Between [tblStay].[TimeIn] And [tblStay].[TimeOut]
GROUP BY tblTime.Hour;

tblTime is just a list of each hour of the day
tblStay has two columns, timeIn, timeOut

I, for the life of me, cannot get a zero to return. I've tried Nz all
kinds of ways and can't get it to go.

Any ideas?
 
M

Marshall Barton

alphamisanthrope said:
Here's my statement:
SELECT tblTime.Hour, Count(*) AS HowMany
FROM tblStay, tblTime
WHERE tblTime.Hour Between [tblStay].[TimeIn] And [tblStay].[TimeOut]
GROUP BY tblTime.Hour;

tblTime is just a list of each hour of the day
tblStay has two columns, timeIn, timeOut

I, for the life of me, cannot get a zero to return. I've tried Nz all
kinds of ways and can't get it to go.


Try using:

SELECT tblTime.Hour, Count(*) AS HowMany
FROM tblTime LEFT JOIN tblStay
ON tblTime.Hour >= [tblStay].[TimeIn]
And tblTime.Hour <= [tblStay].[TimeOut]
GROUP BY tblTime.Hour
 
A

alphamisanthrope

Thanks for your help, but there's a problem,

That statement put a 1 when a 0 should be.
 
M

Marshall Barton

alphamisanthrope said:
Thanks for your help, but there's a problem,

That statement put a 1 when a 0 should be.


Arrggghhhh. The count was supposed to be
Count(tblStay.TimeIn)
 
A

alphamisanthrope

Arrggghhhh. The count was supposed to be
Count(tblStay.TimeIn)

That did it! Bless you. Now I just need some Rogaine for all the hair
I've pulled out.

Thanks again.
 
M

Marshall Barton

alphamisanthrope said:
That did it! Bless you. Now I just need some Rogaine for all the hair
I've pulled out.

Thanks again.


You're welcome.

Do you really think Rogaine will do the job? If it will,
I'll have to run out and buy a couple of palettes of the
stuff ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top