问题
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