Results 1 to 4 of 4
  1. #1
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77

    Query with conditions that does not affect what records are shown but what an expression will return

    I am trying to do a expression in a query that will show me one thing if a certain criteria is met, and another thing if the criteria is not met. Is this possible?

    More specifically:

    Assume I have a table with two columns, A and B. They are both numeric.
    Values in column A are never null. There is always a number.
    Values in column B may be null and may be a number.

    I need an expression C:
    IF the value in column B is not null, then the expression in column C must = value of column B.
    ELSE IF the value in column B is null, then the expression in column C must = value of column A.

    This seems like a simple enough task, but I have no idea how to go about it.



    Any help would be appreciated

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    How about

    Nz(ColumnB, ColumnA)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Code:
    , IIf(B IS NULL,A,B) as C,

  4. #4
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77
    This works wonderfully. Thank you very much. Such a powerful tool, and yet so simple even I can understand them.
    I have a lot of experimenting to do with these two babies, I think they might be very useful in other areas of my project as well. Thank you

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

Similar Threads

  1. Replies: 21
    Last Post: 03-14-2016, 01:33 PM
  2. Replies: 9
    Last Post: 08-19-2014, 12:41 PM
  3. Replies: 1
    Last Post: 06-27-2013, 09:33 AM
  4. Query Expression to return only the latest data
    By Brinleigh217 in forum Queries
    Replies: 6
    Last Post: 03-23-2012, 02:53 PM
  5. Expression with multiple conditions
    By techexpressinc in forum Queries
    Replies: 3
    Last Post: 06-19-2009, 08:33 PM

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