Results 1 to 5 of 5
  1. #1
    sirlosi is offline Novice
    Windows XP Access 2002
    Join Date
    Mar 2011
    Posts
    6

    if statement

    I need help writing an if statement in a query for a category field that has multiple values. I am looking for an equation that will look at the category field and return L if the category is (LB, NF, WC, TFA, TFU, or TSU) if not return value in category field.

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You will need to use the IIF() function if I understand correctly what you are trying to do. The query may look something like this. You will have to substitute your own table and field names

    SELECT Table5.pkRecID, IIF(Table5.category in ("LB","NF","WC", "TFA","TFU" ,"TSU"),"L", Table5.category)
    FROM Table5;

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    <snip>
    SELECT Table5.pkRecID, IIF(Table5.category in ("LB","NF","WC", "TFA","TFU" ,"TSU"),"L", Table5.category)
    FROM Table5;
    I think you will also have to name the calculated field:

    Code:
    SELECT Table5.pkRecID, IIF(Table5.category in ("LB","NF","WC", "TFA","TFU" ,"TSU"),"L", Table5.category) AS FIELD1 FROM Table5;
    Of course, change "FIELD1" to what you want the field named.

  4. #4
    sirlosi is offline Novice
    Windows XP Access 2002
    Join Date
    Mar 2011
    Posts
    6
    Works great. Thanks for the help.

  5. #5
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome. Glad we were able to help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with IF statement
    By mkallover in forum Programming
    Replies: 7
    Last Post: 01-04-2011, 04:47 PM
  2. SQL like statement?
    By Cojack in forum Queries
    Replies: 4
    Last Post: 09-21-2010, 04:45 AM
  3. Help with Iif statement
    By tmcrouse in forum Queries
    Replies: 2
    Last Post: 09-02-2010, 09:00 AM
  4. IIf Statement...HELP!
    By bdhFS in forum Queries
    Replies: 5
    Last Post: 05-19-2010, 07:55 AM
  5. IIF statement
    By james1982 in forum Access
    Replies: 1
    Last Post: 07-20-2009, 09:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums