Results 1 to 7 of 7
  1. #1
    keith2511 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2017
    Location
    UK
    Posts
    45

    How to treat null values in query joins

    I have a database were the tables that contain volatile data include codes which are used in joins to other tables that hold the description associated with that code.



    There are instances in the volatile data where fields that contain codes are rightly empty.

    In these instances I would like the query results to show a piece of text such as "None" or "N/A" but this is beyond my understanding of the software.

    Can this be done and if so, how?

    Thanks in advance.

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You cannot join on null fields so you will need to rethink your query. You can create an initial query which changes nulls to None but then you can't use it in a join. It may help if you created a code with the description None so that your joins will be valid.

  3. #3
    keith2511 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2017
    Location
    UK
    Posts
    45
    Thanks for your reply. I am not the data owner nor have any influence on changing nulls to another value.
    I was thinking more about if it is possible to use an IF statement that checks for a null and returns a "none" in the query results, else returns the value of the join if the field is not null.

    Is that possible?

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    not quite clear what you are asking, some example data and the required outcome would be helpful.

    It may be that a left join will do what you require

    SELECT TableA.Joinfield, nz(TableB.Joinfield,"None") AS BJoinfield
    FROM TableA LEFT JOIN TableB ON TableA.Joinfield=TableB.Joinfield

    Alternatively you can use the format property to display None if null. For text it would be

    @:"None"

    and for Numbers

    0;0;0;"None"

    Benefit of using the format property is it does not change the underlying value which may or may not be useful for your project

  5. #5
    keith2511 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2017
    Location
    UK
    Posts
    45
    Thanks for your reply Ajax.

    Below is an example of data and required results. Just to confirm that I have no control over the data and have to live with what I receive.

    Click image for larger version. 

Name:	access query.PNG 
Views:	15 
Size:	12.8 KB 
ID:	32348

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    in that case, my initial suggestion would work

    SELECT TableA.Surname, nz(TableB.Make,"None") AS BJoinfield
    FROM TableA LEFT JOIN TableB ON TableA.Car_Type=TableB.Car_Type

  7. #7
    keith2511 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2017
    Location
    UK
    Posts
    45
    Thank you Ajax. It has worked

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

Similar Threads

  1. Getting Access to Treat Null as a Zero
    By LandShark506 in forum Queries
    Replies: 1
    Last Post: 06-22-2017, 12:16 PM
  2. Replies: 15
    Last Post: 10-22-2012, 06:06 PM
  3. Query and Null Values
    By ydrasil281 in forum Queries
    Replies: 1
    Last Post: 08-06-2012, 03:32 PM
  4. Query with null values
    By Psyclone in forum Queries
    Replies: 3
    Last Post: 03-30-2011, 09:57 PM
  5. Null Values in query
    By LesleaOH in forum Queries
    Replies: 0
    Last Post: 10-19-2009, 04:45 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