|
Note, this is an Access DB and I have two date columns called 'Date_From' and 'Date_To'. When I try to query the two date columns using the OR statement, my other criterions (TYPE, RESULTS) does not work. Instead of getting filtered with the dates in between and the criterions, I get all the dates in BETWEEN and all the criterions I did not ask for. What gives? Can anyone help me? Thanks for your time!
Oh...I seperated the SQL statement so you an easily see it.
<---SQL--->
SELECT ID, Type, Date_From, Date_To, LastName, FirstName,
Hours, Results
FROM PTO
WHERE Type ='PTO' AND Results='Accepted' AND Date_From BETWEEN #" + strFromMonth + "# AND #" + strToMonth + "# OR Date_To BETWEEN #"+ strFromMonth + "# AND #"+ strToMonth + "#
GROUP BY FirstName, LastName, Type, Date_From, Date_To, Email, Hours, ID, Results
ORDER BY " + strOrderBy
<---End of SQL--->
|
|
|
Try this:
WHERE Type ='PTO' AND Results='Accepted' AND (Date_From BETWEEN #" + strFromMonth + "# AND #" + strToMonth + "# OR Date_To BETWEEN #"+ strFromMonth + "# AND #"+ strToMonth + "#)"
Notice I added parenthesis around your dates. That makes all the difference.
|
|
|
|
|
I swear I tried that. Now it works. Thanks for your time!
|
|
|
|
|
|
|
// |