Filter for Same Value in Two Fields

D

Dave

There are two fields in my query. "From" and "To". For sake of ease, let's
say both these fields are US Cities. How can I pull all the records that show
shipped "From" Denver and that show shipped "To" Denver? Thank you in advance.
 
D

Dave

Just puting Denver in the criteria sections does not work. I need to write an
If statement of some kind (ie- If "From" or "To" = Denver Then show). Or an
Iif statement (Iif ("From" or "To" = Denver, show, hide). How would I do
this? Thanks.
 
J

John W. Vinson

Just puting Denver in the criteria sections does not work. I need to write an
If statement of some kind (ie- If "From" or "To" = Denver Then show). Or an
Iif statement (Iif ("From" or "To" = Denver, show, hide). How would I do
this? Thanks.

Please define "does not work" - in particular open the query in SQL view and
post the SQL here, and indicate what works and what doesn't work. Or, post the
relevant fieldnames of your table (From, To, and the fields that you want to
show, and any other fields to which you're applying criteria).

The OR logic *is the correct solution*, it does work correctly (if done
correctly), it does not require any IF or conditional logic.
 
J

John W. Vinson

Your initial reply did not show up until after my last post. Thank you, the
method you suggested in that post worked.

And it is the method that I suggested in my response as well, which must have
been phrased confusingly... sorry about that, and glad that John Spencer's
good advice worked for you!
 
K

KenSheridan via AccessMonster.com

Do you mean AND or OR? We often use AND in everyday English when we really
mean a Boolean OR. Using AND here would return only those items which are
shipped from Denver to Denver because the value is the same in both columns.
That sounds less likely, so I think you probably want an OR, items shipped
from Denver or items shipped to Denver. So the query would be something like:


SELECT *
FROM [YourTable]
WHERE [From] = "Denver"
OR [To] = "Denver";

In query design view an OR operation is built when you include the value on
the first and second criteria row of the design grid respectively for each
column, e.g. you'd put "Denver" in the first criteria row of the From column
and in the second criteria row of the To column; or vice versa, the result is
the same.

Putting "Denver" in the first criteria row of both columns would build a
Boolean AND operation, i.e. items shipped from Denver to Denver.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top