Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

"SELECT * FROM Transactions WHERE DATE > '" & dteDate & "'"

 

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

 

Thanks

Posted

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:

 

"SELECT * FROM TRANSACTIONS WHERE DATE > #" & dteDate & "#"

Posted

If you are using Oracle, use the following syntax:

 

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

 

The general format is:

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...