Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 problem with BETWEEN dates

Author  Topic 

ArthurKay
Starting Member

7 Posts

Posted - 2007-05-10 : 11:11:43
I'm still somewhat new to SQL, but I understand basic queries to a Microsoft Access database.

I am trying to query my table for dates in a specific range (a particluar month).

My SQL statement is as follows:

strSQL = "SELECT * FROM Campaigns WHERE Send_Date BETWEEN 5/1/2007 AND 6/1/2007 ORDER BY Send_Date DESC"

I will be replacing the dates "5/1/2007" and "6/1/2007" with user defined dates, but right now I can't get this to work.

What am I doing wrong with the BETWEEN xxx AND xxx call?

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-10 : 11:14:20
You need to delimit date literals with # symbols. Otherwise, you are just dividing 3 numbers together.

i.e.,

where date between #5/1/2007# and #6/1/2007#



- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

ArthurKay
Starting Member

7 Posts

Posted - 2007-05-10 : 11:32:35
Worked like a charm!

Thanks!!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-11 : 06:15:42
Also note that in SQL Server or in other DBMS, you need to use single quote

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

wolfnero
Starting Member

6 Posts

Posted - 2007-05-11 : 10:42:06
I use this sintax:
... where date between #2007/1/5# and #2007/1/6# ....
and works!!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-11 : 10:46:31
quote:
Originally posted by wolfnero

I use this sintax:
... where date between #2007/1/5# and #2007/1/6# ....
and works!!!



Yes YMD format will always work everywhere

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -