I am trying to add a function to my JOIN
condition in an MS Access query.
As a simplified example, consider that I have:
tblChild
and tblParent
and tblGrandparent
tblChild
has both a nullable ParentId
and GrandparentId
depending on which one is known. I'm trying to write a query to take the more specific relationship provided. If this were TSQL it would be:
SELECT
columns
FROM
tblChild AS c
LEFT OUTER JOIN
tblParent AS p
ON p.[Id] = c.[ParentId]
LEFT OUTER JOIN
tblGrandparent AS gp
ON gp.[Id] = COALESE(p.[GrandParentId], c.[GrandParentId])
but I can't figure out how to get a COALESCE
style function into the JOIN
condition in Access. Here is what I would have expected to work:
SELECT
columns
FROM
(tblChild AS c
LEFT OUTER JOIN
tblParent AS p
ON p.[Id] = c.[ParentId])
LEFT OUTER JOIN
tblGrandparent AS gp
ON gp.[Id] = Nz(p.[GrandParentId], c.[GrandParentId])