How to compare fields with Null values in Access

旧时模样 提交于 2021-02-11 14:32:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!