codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Access SQL Between Using Dates  jimmytieu at 19:12 on Wednesday, May 26, 2004
 

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--->

  Re: Access SQL Between Using Dates  Troy Wolf at 20:17 on Wednesday, May 26, 2004
 

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.
Troy Wolf: site expert
SnippetEdit Website Editor


  Re: Access SQL Between Using Dates  jimmytieu at 20:33 on Wednesday, May 26, 2004
 

I swear I tried that. Now it works. Thanks for your time!








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: internationalization for password validation
•  calculating total black pixels in an image
•  Re: SOAP Webservices by PERL
•  Re: caps lock and API
•  Re: need help, will pay!
•  Re: filling out a pdf form with html javascript ?
•  counting pixels
•  Calling SP from ASP that calls multiple transactions
•  Please help me in putting javascript validation for dynamic radio button


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007