Access 2007 - Left Join to a query returns #Error instead of Null

前端 未结 3 1469
傲寒
傲寒 2020-12-02 01:34

Similar to this question, but their problem with the query was never fully solved:

#Error showing up in multiple LEFT JOIN statement Access query when value should b

3条回答
  •  抹茶落季
    2020-12-02 01:48

    While the query should return Null based on the join type, as Allen Browne states in his article, Bug: Outer join expressions retrieved wrongly,

    "Instead, it behaves as if [the JET query optimizer] is evaluating the expression after it has returned the results from the lower-level query."

    Consequently, you must select the calculated field using an expression that will evaluate to Null if the right-side of the join doesn't match the left-side.

    Using your pared-down code as an example:

    SELECT 
    Month.Chain,
    DateDiff("m",QueryDates.StartDate,QueryDates.EndDate)+1 AS CasesPerMonthPerStore
    FROM
    QueryDates,
    MonthRange;
    
    SELECT
    Chains.Chain,
    IIf(IsNull(ErrorQuery.Chain),Null,ErrorQuery.CasesPerMonthPerStore)
    FROM
    Chains
    LEFT JOIN
    ErrorQuery
    ON Chains.Chain=ErrorQuery.Chain;
    

提交回复
热议问题