Compare 4 columns for equality

G

Guest

I was wondering if there was any other way (other than IIF statement), to
check if the values in 4 specific columns are equal? If I had 10 columns, an
IIF statement would be very lengthly.

E.g. A B
Name1 Jane Jane
Name2 Jane Jane
Name3 Jane Jane
Name4 Bob Jane

Name are the columns, A & B are the rows

A would return FALSE or No, B would return Yes or TRUE.

Thanks,
Jessica
 
J

John Spencer

IIF statement would probably be the simplest to implement AS LONG AS none of
the values was null.

IIF (A=B and B=C and C=D and D=E,True,False)
 
G

Guest

Does anyone have any ideas, if there are nulls?

John Spencer said:
IIF statement would probably be the simplest to implement AS LONG AS none of
the values was null.

IIF (A=B and B=C and C=D and D=E,True,False)
 
J

John Spencer

If there are nulls, what results do you want?
A = "jessica"
B is Null
C = "Jessica"

Is this a match or not a match? If the above case is not a match, then the
following should return what you want. It will also return true if all the
fields are null.

IIF (Nz(A,"")=Nz(B,"") AND Nz(B,"")=Nz(C,""),True,False)

If you want to ignore null values in the comparison, then things get more
complicated and I would handle the whole thing with a custom function and
pass in an array of values and do the comparison there. You need to state
your rules clearly.

-- All Nulls is a match (or not)
-- One or more nulls are ignored in the comparison
-- All non-null values must match (same as above)
 

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