Results 1 to 10 of 10
  1. #1
    jeffoest is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    5

    Conditional Query?

    Hi all, first time poster here. I'm not a super experienced Access user - but know enough to join a few tables and combine data with (no SQL - just using the Query Design view). So here is my question.



    If I have just two tables that I want to combine where both have fields that represent the same thing - let's say "Project Sponsor". What I want to do have happen is that if Table1 has that field populated, then use that population in the result. However if Table1 does NOT have it populated but Table 2 DOES, then I would like to use the result from Table 2. In other words, the result is just one table with one field "Project Sponsor". But it's kind of conditional I suppose.

    Thanks for any help - hope I explained it well enough!

  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,642
    If the first is Null:

    Nz(Table1.FieldName, Table2.FieldName)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jeffoest is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    5
    Thanks! Do I have to put this code into the SQL or can I somehow enter it in the query design view?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    It can be put in design view:

    Whatever: Nz(Table1.FieldName, Table2.FieldName)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jeffoest is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    5
    Ok - playing with it but having trouble... As you said If the first is Null:

    Nz(Table1.FieldName, Table2.FieldName) - but I want the first if it's not null, right?

    I'm sorry for being so needy - but where in Design View do I put this equation? Tried "Criteria but that didn't work"....

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You put it in the field row, in a new column.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jeffoest is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    5
    OK - I did that and put the following expression into the field row...
    [Nz(Epics.Sponsor,SC Workbook.Sponsor)] which correspond to my table names and field names.

    It didn't seem to work without the brackets at all. But, now when I run the query I get an error:
    " is not a valid name. Make sure that it does not include invalid characters....

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Try:

    Whatever: Nz(Epics.Sponsor,[SC Workbook].Sponsor)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    jeffoest is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    5
    Holy cow - I think we have a winner! Paul - thanks SO much! - Jeff

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Happy to help Jeff!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Conditional Query with conditional results
    By Jeff_in_KCMO in forum Queries
    Replies: 4
    Last Post: 09-10-2014, 01:44 PM
  2. Replies: 6
    Last Post: 05-26-2013, 09:10 PM
  3. Conditional calculations in a query?
    By Datech in forum Queries
    Replies: 3
    Last Post: 06-17-2012, 09:39 PM
  4. Conditional Update Query
    By TheShabz in forum Queries
    Replies: 6
    Last Post: 01-24-2012, 12:11 AM
  5. Conditional Query
    By thegladiator in forum Queries
    Replies: 1
    Last Post: 01-14-2011, 11:44 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