Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query to exclude 2 strings of text

Status
Not open for further replies.

Zorro1265

Technical User
Nov 14, 2000
181
US
I have a query that I qant to exlcude 2 text strings. I use the following.

Not Like "w*" Or Like "*chagrin"

It exlcudes the first but not the second. If I reverse their order it still excludes the first not the second. If I use <> its the same deal I can exlcude the first and then when I add a second the excludes doesn't work at all. Whats the trick? Zorro
 
Try:

Not Like &quot;w*&quot; Or Not Like &quot;*chagrin&quot;

Nick
 
I am wondering now if it should be:

Not Like &quot;w*&quot; AND Not Like &quot;*chagrin&quot;

Nick
 
Did that and it didn't work either. I just tried

Not (Like &quot;w*&quot; Or Like &quot;chagrin*&quot;) and that worked. Then when I saved the query access converted it to say this in the field row...
([qryPatient Encounter].[Facility]) Like &quot;w*&quot; Or ([qryPatient Encounter].[Facility]) Like &quot;chagrin*&quot;

criteria was set to false

If someone could explain I would appreciate it greatly. Zorro
 

Access just changed the Boolean expression to an equivalent expression. The next three statements are equivalent.[ol][li]Where Not (A OR B) = True
[li]Where (Not A AND Not B) = True
[li]Where (A Or B) = False[/ol]In other words

Where [Facility] Not Like &quot;w*&quot;
AND [Facility] Not Like &quot;*chagrin&quot;

is equivalent to

Where ([Facility] Like &quot;w*&quot;
OR [Facility] Like &quot;*chagrin&quot;) = False

The &quot;= True&quot; portion of the first statement is assumed. That statement can also be rewritten as

Where ([Facility] Not Like &quot;w*&quot;
AND [Facility] Not Like &quot;*chagrin&quot;) = True

I think the Access version is simpler and easier to understand. However, it is surprising to see your code changed so drastically but it is logical. :)I Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Thanks Terry it just spooked me when I got the thing to work and all of a sudden it was changed! Zorro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top