I can't figure out why I am receiving a syntax error in access sql for the following nested IIF - it works if I remove the top line and closing parenthesis... Thanks
IIF(
[Home Phone] IS NULL
AND [H1 Cell Phone] IS NULL
, [Home Phone]
, IIF(
[H1 Cell Phone] IS NOT NULL
, [H1 Cell Phone] & ' (m)'
, [Home Phone] & ' (h)'
) AS Phone
)
Try moving the "AS Phone" part outside of the closing parenthesis. It looks like your IIf can be split up as:
IIF(
[Home Phone] IS NULL AND [H1 Cell Phone] IS NULL, -- Conditional
[Home Phone], -- Conditional true If they're both null, why are you displaying null here?
-- Conditional false
IIF(
[H1 Cell Phone] IS NOT NULL, -- Conditional
[H1 Cell Phone]&' (m)', - True
[Home Phone]&' (h)' - False
) AS Phone --I think the AS Phone part needs to be moved outside the IIF or removed entirely.
)
See http://office.microsoft.com/en-us/access-help/iif-function-HA001228853.aspx for examples on how to use IIF as well.
IIF([Home Phone] IS NULL AND [H1 Cell Phone] IS NULL,[Home Phone],
IIF([H1 Cell Phone] IS NOT NULL, [H1 Cell Phone]&' (m)', [Home Phone]&' (h)')) AS Phone
Parenthesis is misplaced. You must trouble shoot this in pieces. Find parts taht work, and build up.
Remember IIF - is constructed with the format: IIF(SOME_TEST,TRUE_CONDITION,ELSE_FALSE_CONDITION)
At first glance, you are missing a closing paranthesis..
IIF([Home Phone] IS NULL AND [H1 Cell Phone] IS NULL,[Home Phone],
IIF([H1 Cell Phone] IS NOT NULL, [H1 Cell Phone]&' (m)', [Home Phone]&' (h)') AS Phone
))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.