Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2009
    Posts
    7

    Smile Unanswered: Conditions (if else)

    Hi,

    I am trying to compute value in my access db table. I have a cloumn in table "Final Value", "Segment", "List Price", "Invoice Price", "Product ID" And "Units"

    Entire column of Final value is empty, what i need to update is that.

    if Segment = "A" then Units * List Price
    if Product_ ID = "BG" then Units * List Price
    Else
    Invoice Price * Units.

    Can anyone please help the Easiest & fastest way (In terms of Query run) to do the same.

    Regards
    santosh

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    try an iif
    iif(Segment = "A",Units * List Price,iif(Product_ ID = "BG",Units * List Price, Invoice Price * Units))
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jan 2009
    Posts
    7
    I have typed the formula in the desgine of the table in "Default value"

    it says "Expression contains invalid syntex:
    Entered an operend without an operator.

    pls help.
    Last edited by sksoni75; 01-16-09 at 06:45.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have a look at the help file for IIF
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you can simplify this --

    iif(Segment = "A",Units * List Price,iif(Product_ ID = "BG",Units * List Price, Invoice Price * Units))

    to this --

    iif(Segment = 'A' OR Product_ ID = 'BG', Units * [List Price], Units * [Invoice Price])

    notice how i supplied the missing identifier delimiters (square brackets) because of the spaces in the column names

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Don't you have to delimit the SQL string component?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    who, me? what is an SQL string component?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Kind like this:

    iif(Segment = 'A' OR Product_ ID = 'BG', "Units *[List Price]", "Units * [Invoice Price]")
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  9. #9
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    why would you do that?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •