SQL statement with multiple WHERE statements

  • Thread starter Thread starter thomasp
  • Start date Start date
T

thomasp

I have a MS Access table with the fields, ID, ATime, and ADate and I want to
select records between a certain date and time. Will someone show me the
proper syntax for the SQL statement. I need to construct the sql statement
in VB.NET 2005. I can write one that pulls records between a set of dates,
but not a certain time on the start date and a certain time on the endDate.

Thanks

Thomas
 
Any particular reason you have your timestamp separated into the two
fields Atime and ADate? I generally prefer to have a single datetime
field that combines both as it makes querying much easier--something
like this:

SELECT * FROM MyTable WHERE ADateTime BETWEEN "2005-07-01 12:34:56" AND
"2005-07-07 17:18:19"

If you need to show only the date or only the time you can use DATEPART
function or format fucntion in your application.

If for some unfathomable reason you must keep the date and time separate
it gets more complicated. You have to do something like this:

SELECT *
FROM MyTable
WHERE (ADate = "2005-07-01" AND ATime > "12:34:56")
OR (ADate > "2005-07-01" AND ADate < "2005-07-07"
OR (ADate = "2005-07-07" AND ATime < "17:18:19")

This will do what you want but is more complicated. Unless you have a
really really good reason to keep the fields separate then I suggest
using a field with both Date and Time combined.

will NOT work because every day in the middle will be
 
Back
Top