Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
908 views
in Technique[技术] by (71.8m points)

ms access - Inconsistent results when checking for Null values (Jet DAO vs. ACE DAO)

In a VB6 program accessing an MDB file, the following SQL query is being executed:

> Select * FROM [table1] WHERE ([type] = 1 OR [type] = 2 OR [type] = 6)
> AND ([notes] = Null OR [notes] = '0') AND [date] >= 
> cvdate('09/03/2013') ORDER BY [date], [column2]

If I reference Microsoft Access 14.0 Object Library in the program the returned recordset has 0 rows.

If I reference Microsoft DAO 3.51 Object Library the returned recordset has over 100 rows.

What is the reason for this difference? Is there a difference between the way the two providers handles the test for Null? Is this a breaking change for ACE DAO accessing older MDB files?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

WHERE ... [notes] = Null is non-standard SQL. Null propagation can potentially force any expression involving Null to return Null. Therefore the expression [notes] = Null (which you intended to be a boolean expression) could very well return Null, which is neither True nor False.

How the query processor handles that Null value may indeed differ from one database engine to another: it could interpret Null as False, or it could just ignore the result, or it could trigger an error. Note also that null propagation could collapse your entire WHERE clause to Null if...

(some other condition) AND (Null)

...evaluates to Null.

Standard SQL would be ([notes] IS NULL) and a Jet/ACE equivalent would be IsNull([notes]). Both of these will always return either True or False.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...