Criteria?

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I have a table with a number of fields. I want to be
able to select certain records for certain zipcodes (ZIP)
and also exclude certain people belonging to certain
fields (ie: GOV, IP, MISC). I started the criteria with
the ZIP and then did GOV (Not like "COM") and some others
but the COM people and others still show up. The zip
codes are right but the rest isn't. Could somebody give
this dummy a little help. Thank you.
 
SELECT NC97.FNAME, NC97.LNAME, NC97.ADDRESS, NC97.CITY,
NC97.STATE, NC97.ZIP
FROM NC97
WHERE (((NC97.ZIP)>="89001" And (NC97.ZIP)<="89044") AND
((NC97.GOV)<>"COM" Or (NC97.GOV)="SE" Or (NC97.GOV)="AS"
Or (NC97.GOV)="GOV" Or (NC97.GOV)="CONG") AND ((NC97.MP)
<>"MP" Or (NC97.MP)="MPX") AND ((NC97.PI)<>"PI") AND
((NC97.MISC)<>"VI")) OR (((NC97.ZIP)>="89046" And
(NC97.ZIP)<="89048")) OR (((NC97.ZIP)>="89050" And
(NC97.ZIP)<="89199")) OR (((NC97.ZIP)="89422")) OR
(((NC97.ZIP)="89415")) OR (((NC97.ZIP)="89701"));
 
I would suggest you think logically and use Boolean
algebra to simplify your criteria as much as possible
before applying the criteria to the Query.

If you appply Boolean algebra at the criteria:

((NC97.GOV)<>"COM" Or (NC97.GOV)="SE" Or
(NC97.GOV)="AS" Or (NC97.GOV)="GOV" Or
(NC97.GOV)="CONG")

The whole big expression above is equivalent to:

(NC97.GOV <> "COM")

The parentheses indicate the order of operations as well
so you need to be aware of which order you want the
criteria to be evaluated.

HTH
Van T. Dinh
MVP (Access)
 
Back
Top