簡體   English   中英

MS Access 2013:嵌套的IIF語法錯誤

[英]MS Access 2013: Nested IIF Syntax Error

我無法弄清楚為什么我在訪問SQL中收到以下嵌套IIF的語法錯誤-如果我刪除了頂行並關閉了括號,它會起作用...謝謝

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
)

嘗試將“ 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/zh-cn/access-help/iif-function-HA001228853.aspx

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

括號放錯了位置。 您必須為此付出很多努力。 找到可以工作的零件,然后進行組裝。

記住IIF(SOME_TEST,TRUE_CONDITION,ELSE_FALSE_CONDITION)以以下格式構造: 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

))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM