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

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;

Leave a Comment