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

前端 未结 2 1511
小鲜肉
小鲜肉 2020-12-21 08:33

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)         


        
相关标签:
2条回答
  • 2020-12-21 09:27

    DAO 3.51 is way outdated. It was replaced by DAO 3.6 many years ago. Use 3.6 instead and then see whether this version of your query returns the same results from both DAO 3.6 and ACEDAO:

    SELECT *
    FROM [table1]
    WHERE
            [type] IN (1,2,6)
        AND ([notes] Is Null OR [notes] = '0')
        AND [date] >= cvdate('09/03/2013')
    ORDER BY [date], [column2];
    
    0 讨论(0)
  • 2020-12-21 09:37

    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.

    0 讨论(0)
提交回复
热议问题