Invalid use of null in where statement; no null values

感情迁移 提交于 2019-12-20 07:41:37

问题


I have the following problem:

I am using two queries to parse imported data, they are both selecting data The imported dataset is pretty complex, but this reproduces the error.

QueryA:

SELECT CDbl(FieldA) As DblA, Imported.* From Imported WHERE FieldA IS NOT NULL

QueryB:

SELECT * FROM QueryA WHERE DblA > 7 AND DblA < 600

QueryA runs fine, QueryB throws an invalid use of null error

If I insert the results from QueryA into a table and run QueryB against that I do not receive the error, however, this is not desired.

If I remove the WHERE from QueryB it runs fine.

Is there a different workaround for this? Or should I just accept the redundant table?


回答1:


Ah, fixed it, still don't know why.

Changed QueryA

SELECT CDbl(Nz(FieldA, 999)) As DblA, Imported.* From Imported WHERE FieldA IS NOT NULL AND Nz(FieldA, 999) <> 999

As far as my SQL knowledge goes this shouldn't make any difference, but it does. If someone can explain it I would welcome it.

The 999 instead of 0 is because else I would get division by 0 errors in other functions (while really Access shouldn't be running any functions with it since it's filtered out).




回答2:


Try this query.

SELECT * FROM QueryA WHERE DblA > 7 AND DblA < 600 AND Dbla IS NOT NULL


来源:https://stackoverflow.com/questions/44804170/invalid-use-of-null-in-where-statement-no-null-values

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