Quick SQL String Question

Disasterpiece

Well-known member
Joined
Apr 2, 2003
Messages
47
Location
Blacksburg, VA
Can you use (>) and (<) in SQL statements when refering to a Date format column?

Say I want to get all of the rows from only a certain date forward, would this work:

Code:
"SELECT * FROM Transactions WHERE DATE > " & dteDate & ""

If not, would I have to use a BETWEEN statement instead?

Thanks
 
Yes, you can use the > < operators on date fields. However, depending on your data source, you have to specify that the value being evaluated is a date. For example, in Access, you would write the following:

Code:
"SELECT * FROM TRANSACTIONS WHERE DATE > #" & dteDate & "#"
 
If you are using Oracle, use the following syntax:

Code:
"SELECT * FROM TRANSACTIONS WHERE DATE > {ts " & dteDate & "}"

The general format is:

Code:
"SELECT * FROM TRANSACTIONS WHERE DATE > {ts 2002-11-06 18:24:25}"

There are, of course, various formats you can use. But use "-" instead of "/" as separators. From my experience, Oracle likes them better. Hope that helps.
 
Back
Top