Home All Groups Group Topic Archive Search About

SQL statement with multiple WHERE statements

Author
6 Jul 2005 1:37 PM
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

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
      ------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Author
6 Jul 2005 7:14 PM
MSH
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

*** Sent via Developersdex http://www.developersdex.com ***
Are all your drivers up to date? click for free checkup

Author
6 Jul 2005 8:12 PM
thomasp
The two being in separate fields is not under my control.

Thanks,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
      ------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Bookmark and Share