Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql access how to return between dates

Tags:

sql

vba

ms-access

How do I specify a date range in MS Access? Is the below query correct? Do I have to put "2/1/2010" in quotes? Or do I have to do something like date(2/1/2010)?

SELECT [Occurrence Number] as Fld
  FROM [Lab Occurrence Form]
 WHERE [Practice Code]="ACCIM"
   AND [1 0 Preanalytical (Before Testing)]="1.1 Specimen Mislabeled"
   AND ([Occurrence Date] Between 2/1/2010 and 2/28/2010);

the following gives me a type mismatch

SELECT [Occurrence Number] as Fld FROM [Lab Occurrence Form] WHERE [1 0 Preanalytical (Before Testing)]="1.1 Specimen Mislabeled" AND [Occurrence Date] between "1/1/2009" and "2/2/2010";
like image 318
Alex Gordon Avatar asked Jul 02 '10 19:07

Alex Gordon


2 Answers

ms-access uses the Jet engine which uses # for date literal:

SELECT Orders.*
  FROM Orders
 WHERE Orders.OrderDate Between #3/1/96# And #6/30/96#;
like image 159
Alex W Avatar answered Oct 11 '22 16:10

Alex W


AND ([Occurrence Date] Between #2/1/2010# and #2/28/2010#

This is how you tell Access, to interpret something as date time.

like image 35
shahkalpesh Avatar answered Oct 11 '22 15:10

shahkalpesh