Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / March 2007

Tip: Looking for answers? Try searching our database.

nested OR in queries

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vgraybeal - 27 Mar 2007 18:27 GMT
I have a table that has 20 date fields for each record. I need to select any
record that has a matching date in at least one of those fields so it becomes
a huge OR in a query and I have noticed that I am limited to 9 in a query. Is
there a way to do this efficiently or will I need multiple queries to test
all 20 date fields?
Jeff Boyce - 27 Mar 2007 18:51 GMT
If your table uses multiple date fields, the first thing you'll want to
consider is coming up with a new table!

In a spreadsheet, adding 20 date fields may be the only way to handle a
situation, but you won't get the best use of Access' features and functions
if you don't use well-normalized tables.

You didn't explain much about those 20 fields, but I'll hazard a guess that
they represent different steps or stages or types or categories of dates.
In a relational database (e.g., Access), you'd handle this with something
like:

   tblSomethingDate
       SomethingDateID
       SomethingID (to what does the following date apply?)
       YourDate (don't use "Date" as a field name-this is a reserved word
in Access)
       YourDateTypeID (this is where you put the category you were using 20
fields to show)

If I've mis-interpreted, please post back with a more detailed description.

Regards

Jeff Boyce
Microsoft Office/Access MVP

>I have a table that has 20 date fields for each record. I need to select
>any
[quoted text clipped - 4 lines]
> there a way to do this efficiently or will I need multiple queries to test
> all 20 date fields?
John Spencer - 27 Mar 2007 19:04 GMT
Sounds as if you are using QBE (Design view grid).

Click on any criteria row and then select INSERT Rows from the menu.

This will add an additional criteria row.

The problem here is that you have 20 date fields in one row of data.  It is
probable that you should be storing these dates in another table that
contains the date you are storing, the type of date (DOB, Communion Date,
Date of Graduation, etc) and the primary key value from you present table.
With that structure all you would need is to join the two tables and place
criteria against one field.

Signature

John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

>I have a table that has 20 date fields for each record. I need to select
>any
[quoted text clipped - 4 lines]
> there a way to do this efficiently or will I need multiple queries to test
> all 20 date fields?
John W. Vinson - 27 Mar 2007 19:41 GMT
>I have a table that has 20 date fields for each record.

Then you have a spreadsheet, not a table. Your table design IS WRONG. If you
have a one to many relationship, you need to model it as a one to many
relationship between two tables! "Fields are expensive, records are cheap".

> I need to select any
>record that has a matching date in at least one of those fields so it becomes
>a huge OR in a query and I have noticed that I am limited to 9 in a query. Is
>there a way to do this efficiently or will I need multiple queries to test
>all 20 date fields?

You're not actually limited to 9 - if you insist on using this incorrect table
design, you *can* select one or more rows in the query grid and use the INSERT
ROWS menu option to add more rows. Or you can go into SQL view and edit the
SQL of the query to add multiple more OR's. At some point you'll get the
"Query Too Complex" error though - I'd really recommend that you correct your
table structure!

            John W. Vinson [MVP]
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.