If you clean up your code -- rename your column correlation name 'out' (it's a reserved word), change your keywords to uppercase, etc -- then according to the Mimer SQL-92 validator your SQL is valid Intermediate SQL-92 code. Therefore, you should have a reasonable expectation that this vanilla SQL code would work on any modern SQL implemenation.
Sadly, the Access database engine is not a modern SQL implementation and it is not SQL-92 compliant at any level.
The problem here is that the Access database engine does not support the CASE
expression. Instead, it has a own IIF()
expression. Normally I could make excuses by adding the qualifier, "...because the Access database engine shares an expression service with VBA." The thing is, in this case it doesn't: the IIF()
expression in Access database engine SQL works differently from the VBA IIF()
expression e.g.
SELECT IIF(0 = 1, 55 / 0, 99)
Works fine, returns the value 99.
? IIf(0 = 1, 55 / 0, 99)
Fails with 'Division by zero error'.
FWIW if you do need VBA and SQL to work the same, consider the SWITCH
expression
SELECT SWITCH(1 = 1, 55, TRUE, 55 / 0)
? Switch(1 = 1, 55, TRUE, 55 / 0)
Both fail with 'Division by zero error'.
The Access database engine SQL has expressions not found in VBA (e.g. IS NULL
, IN()
, etc), so why no CASE
expression? We shall probably never know. The Access database engine is poorly documented; specifically, there was never never much to begin with, what we do have is full of errors (material as well as errors of omission) and, because of the engine's age (i.e. old), what documentation exists is gradually disappearing from MSDN and Microsoft's website. The old Jet experts have moved on to other projects.