Hi Frank,
By different, if those are text, is the difference more than just the
case of the text? Access considers "abc" and "ABC" to be equal. If one is
null and the other is not null then the comparison will never be True. Null
means the value is unknown; as opposed to there is no value. It is a
somewhat subtle distinction. An example I like is the Address1, Address2,
Address3 situation. If the address is "123 Main St." then you leave Address2
and Address3 blank because there is no second or third line. But this often
results in Address2 and Address3 being stored in a database as null, which
technically means the second and third lines are not known. Which is not
true because they are known. They are known to be blank. Technically in
that case they should be stored as zero-length strings.
Anyway, when you compare an unknown (null) to a known, there is no way
to know if that unknown value is or is not the same as the known value. So
this should return a null as a result. Which means that the results of the
comparison are not known. But IIf() only provides for a True and a False
value. So with the result of the comparison not being known, it is probably
better to assume False and return the value from that part. (If anyone wants
to disagree with the above because my understanding is wrong, please do so.)
Given all of that, what you may want to do is something like this which
changes nulls into zero-length strings which can indeed be compared:
IIf( ... IIf(IsNull([Previous FAS Snapshot].[Sales Phase]), "",
[Previous FAS Snapshot].[Sales Phase]) <> IIf(IsNull([Current FAS
Snapshot].[Sales Phase]), "", [Current FAS Snapshot].[Sales Phase]), "Y", "N")
Or, if Sales Phase is numeric, you might change the nulls to some value
that will not occur with the real data (maybe -1):
IIf( ... IIf(IsNull([Previous FAS Snapshot].[Sales Phase]), -1,
[Previous FAS Snapshot].[Sales Phase]) <> IIf(IsNull([Current FAS
Snapshot].[Sales Phase]), -1, [Current FAS Snapshot].[Sales Phase]), "Y", "N")
Note that you can use the Nz() function instead of the IIf(IsNull()...,
, ) construct, but that function is not built into the Jet Engine and
therefore requires the query tool to call out to VBA. Which can impact
performance. It also means that if you have to execute the query from
outside of Access for some reason, it will not work with the Nz() function,
but will with the IIf(IsNull()..., , ) construct.
Hope that helps,
Clifford Bass
FrankTimJr said:
What I mean by stops is that when [Sales Phase] is different between the two
tables, the result is returning "N" when it should be returning "Y".
What happens if [Previous FAS Snapshot].[Sales Phase] is null and [Current
FAS Snapshot].[Sales Phase] is not null? Does that impact the IIf statement?
I like the second IIf statement you wrote. I'll give that one a try.
Thanks,
Frank