Multiple Criteria for an IIF Statement in Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • W Sauce
    New Member
    • Oct 2011
    • 2

    Multiple Criteria for an IIF Statement in Access

    I am having trouble with creating an IIF Statement with multiple criteria.

    Ultimately I want it to do the following:

    Code:
    IIF amount<0, 1
    IIF amount>=0 and amount <100, 2
    IIF amount >=100 and amount <1000, 3
    and so on...

    Can anyone help?
    Last edited by NeoPa; Oct 19 '11, 10:34 PM. Reason: Added mandatory [CODE] tags for you
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can nest them together
    Code:
    iif(expression1, 1, iif(expression2, 2, ... and so on))

    Comment

    • W Sauce
      New Member
      • Oct 2011
      • 2

      #3
      Thanks. I tried it, but still got an error. This is what I wrote:

      Code:
      Update EE_Detail_Tab_1
      set STRAT_FIELD=
      IIF([VARIN REPCUR]<0), 1,
      IIF (([VARIN REPCUR]>=0 and [VARIN REPCUR] <100), 2,
      IIF (([VARIN REPCUR] >=100 and [VARIN REPCUR] <1000), 3))
      The error I received was "Syntax error in Update Statement"
      Last edited by NeoPa; Oct 19 '11, 10:33 PM. Reason: OP:mistyped

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Your parentheses are out of place and you have spaces between the function name and the opening parentheses.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32662

          #5
          That's because you haven't nested them properly. Check out your parentheses.

          PS. I presume this is SQL code and not VBA. You didn't mention in your question.

          Comment

          Working...