问题
I have a query that looks at one tables field and matches the second table's field. It looks to see if the fields don't match each other. If there's no match the second table's field must replace the first tables field. I have this working EXCEPT when there's a null value in either of the two tables field. I tried using isNull() on the first table and it does select values that aren't null but if I apply the same function to the second table I get nothing in return.
UPDATE [NAVAIR Deficiencies] INNER JOIN NAVAIR_Deficiencies_Temp ON [NAVAIR Deficiencies].[Unique Deficiency Code] = NAVAIR_Deficiencies_Temp.[Unique Deficiency Code] SET [NAVAIR Deficiencies].[Hull Q] = [NAVAIR_Deficiencies_Temp]![Hull Q], NAVAIR_Deficiencies_Temp.Changed = True
WHERE ((IsNull([NAVAIR Deficiencies]![Hull Q])<>[NAVAIR_Deficiencies_Temp]![Hull Q]));
回答1:
You are experiencing the fact that null <> null
.
You can work around this with IsNull()
, if you are able to define a string value that never appears in both columns:
IsNull([NAVAIR Deficiencies]![Hull Q], '§§§§')
<> IsNull([NAVAIR_Deficiencies_Temp]![Hull Q], '§§§§')
This treats two null value as equals, and considers that a null value is not equal to any non-null value.
Or, you can enumerate all possible situations, using boolean logic
[NAVAIR Deficiencies]![Hull Q]) <> [NAVAIR_Deficiencies_Temp]![Hull Q]
or ([NAVAIR Deficiencies]![Hull Q] is null and [NAVAIR_Deficiencies_Temp]![Hull Q] is not null)
or ([NAVAIR Deficiencies]![Hull Q] is not null and [NAVAIR_Deficiencies_Temp]![Hull Q] is null)
It might be simpler expressed with a negation:
not (
[NAVAIR Deficiencies]![Hull Q]) = [NAVAIR_Deficiencies_Temp]![Hull Q]
or ([NAVAIR Deficiencies]![Hull Q] is null and [NAVAIR_Deficiencies_Temp]![Hull Q] is null)
)
来源:https://stackoverflow.com/questions/63960885/how-to-compare-fields-with-null-values-in-access