Solved Criteria equivalent to BUT

AnilBagga

Member
Local time
Tomorrow, 02:03
Joined
Apr 9, 2020
Messages
223
I have a query with 2 fields on which I want to add a filter criteria

Invoice Unit - Exclude data with value M2N - criteria is <>"M2N" - works

BUT I dont want this filter to work for 3 Customer Codes - say A,B and C.

Meaning filter condition is filter out all records where Invoice Unit is M2N BUT not for customer codes where Invoice unit is M2N AND CustomerCodes are A,B or C

How does one achieve this?
 
use two of the Criteria lines/rows.

one to cover each criteria
 
use two of the Criteria lines/rows.

one to cover each criteria
Can you explain further. What criteria do I add in the Customer Code field. There are hundreds of Customer Codes in the tables. I cannot put "A" and "B" and "C" in the customer code criteria as this will remove all other Customers from the data!
 
WHERE SomeField <> "M2N" Or SomeField = "A" Or SomeField = "B" or SomeField = "C"
In the Designer you can do this on each line of the criteria since each line is an or

<> "M2N"
"A"
"B"
"C"
 
M2N is a seperate field called InvoiceUnit

A, B and C are of another field called CustomerCode

This is the problem
 
Then it looks like this in the designer. Notice field 2 begins a row below.

Code:
Field 1       Field 2

<> M2N
                   A
                   B
                   C

WHERE SomeField <> "M2N" Or SomeOtherField = "A" Or SomeOtherField = "B" or SomeOtherField = "C"
 
You mean A, B, C will be in Or rows under column SomeOtherField
 
Then it looks like this in the designer. Notice field 2 begins a row below.

Code:
Field 1       Field 2

<> M2N
                   A
                   B
                   C

WHERE SomeField <> "M2N" Or SomeOtherField = "A" Or SomeOtherField = "B" or SomeOtherField = "C"
Worked!
 
This is how the QEB looks now and is giving the desired results.

All records where MewarInvUnit = M2N are excluded except if ConsigneeCode = 1048, 1091...or 360167

Records where MewarInvUnit is <> M2N and Consignee Code = 362389 or 360631 are excluded

1606942543140.png
 
That isn't what you asked for originally. What you have now only looks at MewarInvUnit when ConsigneeCode is not one of the two on the first row. The other rows ignore Unit entirely. That may be what you want but creating queries with hardcoded references to primary keys is not useful. You are much better off using criteria that is supplied by fields on a form.

Also if ConsigneeCode is numeric, do not enclose it with double quotes.
Mr Hartman

I want all rows under Consignee Code to also use the filter condition os MewarInvUnit. As I stated before the condition translated should be all records where MewarInvUnit <> M2N but if customer codes are A,B,C , include them and ignore the MewarUnit filter condition. Howw can this be achieved?
 
Where Somefield <> "M2N" and SomeOtherField NOT In("A", "B", "C")
Mr Hartman

Is the screen shot what you suggest?

I think I got got wrong . This query removes all records with MewarInvUnit = M2N.
Records with MewarInvUnit = M2N and ConsigneeCode say 1091 are also removed. But we dont want these 6 customer codes to be filtered out!

I used this query by entering this sequence - Not In (..) in the "Or" row too - Same result!

1607034032160.png
 
That created the string
<> "M2N" AND NOT IN ("1048"....."360167")
I doubt that is what you want. You want an OR conditions

<> "M2N" OR IN ("1048"....."360167")

Code:
<> "M2N"
                   IN (1048"....."360167")

To be clear this is the same as previously done in post #7 only using an OR instead of an IN.
 
That created the string
<> "M2N" AND NOT IN ("1048"....."360167")
I doubt that is what you want. You want an OR conditions

<> "M2N" OR IN ("1048"....."360167")

Code:
<> "M2N"
                   IN (1048"....."360167")

To be clear this is the same as previously done in post #7 only using an OR instead of an IN.
Thank you. I was not aware of the IN function
 
Pat/MajP

I have used the In function exactly as suggested. It works perfectly! Thank you both for your help

Anil
 

Users who are viewing this thread

Back
Top Bottom