MS Access 2013:嵌套IIF语法错误

时间:2014-03-07 22:50:51

标签: sql ms-access ms-access-2013

我无法弄清楚为什么我在以下嵌套IIF的访问sql中收到语法错误 - 如果我删除顶行并关闭括号,它会起作用...谢谢

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
)

3 个答案:

答案 0 :(得分:3)

尝试在右括号外移动“AS Phone”部分。看起来您的IIf可以拆分为:

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.
)

有关如何使用IIF的示例,请参阅http://office.microsoft.com/en-us/access-help/iif-function-HA001228853.aspx

答案 1 :(得分:0)

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

括号错位。你必须把它分成几块。找到有效的部件并进行构建。

答案 2 :(得分:0)

记住IF - 使用以下格式构建:IIF(SOME_TEST,TRUE_CONDITION,ELSE_FALSE_CONDITION)

乍一看,你错过了一个右括号..

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

))