Between WHERE clause

R

red6000

Hi, I have the following SQL

SELECT Activities.TaskName, DSum("TimeSpent","Activities","TaskName = '" &
[TaskName] & "'") AS TotalTime
FROM Activities
WHERE (((Activities.WorkDate) Between [Start Period] And [End Period]))
GROUP BY Activities.TaskName
ORDER BY Val(DSum("TimeSpent","Activities","TaskName = '" & [TaskName] &
"'")) DESC;

However it isn't filtering out the records where the date is outside what I
specify?

Any ideas

Many thanks.
 
R

red6000

Okay, I've simplified my SQL to:

SELECT Activities.TaskName, Sum(Activities.TimeSpent) AS TotalTime
FROM Activities
WHERE (((Activities.WorkDate)="30/07/2006"))
GROUP BY Activities.TaskName;

and this works, but if I change the Where clause to:

WHERE (((Activities.WorkDate) between "30/07/2006" and "01/08/2006"))

It just includes everything?????
 
R

Rick Brandt

red6000 said:
Okay, I've simplified my SQL to:

SELECT Activities.TaskName, Sum(Activities.TimeSpent) AS TotalTime
FROM Activities
WHERE (((Activities.WorkDate)="30/07/2006"))
GROUP BY Activities.TaskName;

and this works, but if I change the Where clause to:

WHERE (((Activities.WorkDate) between "30/07/2006" and "01/08/2006"))

It just includes everything?????

Dates in Access are delimited with # not ". They also have to be in US format
mm/dd/yy or mm/dd/yyyy, or in ISO format yyyy-mm-dd or in a format that uses
alpha characters for the month like dd-mmm-yyyy.

The format you are using dd/mm/yyyy will only be interpretted correctly when the
month is greater than 12. Then Access will "know" that the first part must be
the day. Otherwise it will assume the first part is the month.
 

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