views:

59

answers:

3

Hi,

I have a table in an Access 2007 database. All fields are of type text. Can the following be done using the where clause? If so how?

  • SELECT * from Table1 WHERE (ColumnDate is between 26th and 19th of march 2010)
  • SELECT * from Table1 WHERE (ColumnAge is between 25 and 40)

The usual < <= operators don't seem to work.

Thanks,

+1  A: 
SELECT * from Table1 WHERE ColumnDate between '2010-03-26' and '2010-03-19'
SELECT * from Table1 WHERE ColumnAge between 25 and 40

I don't use Access, so YMMV.

Marcelo Cantos
You don't use Access and you posted SQL that won't run in Access. The first one will work if the column has all the dates stored as yyyy-mm-dd, but not otherwise. The second won't work because the original question said that all the fields are text.
David-W-Fenton
+1  A: 

Try converting ColumnDate to actual date/time with CDate function. Conversion to int can be done with CInt, I guess.

I don't use Access, so it's just a common-sense guess.

Anton Gogolev
Are these inbuilt SQL functions, If so how are they called in a query. An example would be appreciated.
tecno
Actually Anton Gogolev's answer reminded me to put them into my sample. So, he deserves an upvote from me :)
Codesleuth
+2  A: 
SELECT * from Table1 WHERE (CDATE(ColumnDate) BETWEEN #03/26/2010# AND #03/19/2010#)
SELECT * from Table1 WHERE (CINT(ColumnAge) between 25 and 40)

Dates are represented in Access between # symbols in #MM/DD/YYYY#. You should really be storing the date as a date field :)

Codesleuth
Thanks,I need to search for those who are aged between 25 and 40 both included.
tecno
`BETWEEN` results include both outer range values. You should be getting those people aged between 25 and 40.
Codesleuth
Thanks Once again, appreciate it.
tecno