Results 1 to 8 of 8
  1. #1
    newbee is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    4

    Question Left join on two queries and want zeros to populate any data that is blank

    I am combining two queries one has a list of stores, the other has a list of attributes for that store. What I need to happen is if the attribute does not appear for a store then the result would be zero instead of blanks. Is there a way of doing this?

  2. #2
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    YES. substitute the literal value of "0" or 0, depending on the data format, into the field and check for NULL suing the IIF() statement.

    example:

    Code:
    SELECT t1.f1, t1.f2, t2.f1, IIF(t2.f2 IS NULL, "0", t2.f2) as t2.f2 FROM t1 LEFT JOIN t2 on t1.f1 = t2.f1 AND t1.f2 = t2.f2 
    
    WHERE t2.f1 IS NULL
    or, of course you don't need the criteria. the LEFT JOIN will take care of things itself. Unless I'm mistaken, I believe that will work.

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Alternatively, you may be able to use the NZ function also, which you tell it what to return in place of a NULL value, i.e.
    NZ([Field1],0)

  4. #4
    newbee is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    4
    Thanks, I used the first with some changes and it worked. I am going to try the second method on something similar.

  5. #5
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    Quote Originally Posted by JoeM View Post
    Alternatively, you may be able to use the NZ function also, which you tell it what to return in place of a NULL value, i.e.
    NZ([Field1],0)
    this is not a catch all, but I've had unpredictable results with NZ(). I never use it because of this reason. It seems as though NZ() is a function that becomes unpredictable from Access version to Access version.

    I've had issues, but does not mean that anyone else will...

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    this is not a catch all, but I've had unpredictable results with NZ(). I never use it because of this reason. It seems as though NZ() is a function that becomes unpredictable from Access version to Access version.

    I've had issues, but does not mean that anyone else will...I have
    That's odd. I have been using it for years in Access 2000, 2003, and 2007, and cannot ever recall having an issue with it.
    Do you remember the circumstances/situations in which you were experiencing problems?
    If there are situations like you describe, I would like to file those away in my memory banks!

  7. #7
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    Quote Originally Posted by JoeM View Post
    That's odd. I have been using it for years in Access 2000, 2003, and 2007, and cannot ever recall having an issue with it.
    Do you remember the circumstances/situations in which you were experiencing problems?
    If there are situations like you describe, I would like to file those away in my memory banks!
    no I don't remember the scenario. but that's not the first time I've heard that either. no idea what's going on with it...

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    no I don't remember the scenario. but that's not the first time I've heard that either. no idea what's going on with it...
    Hmmm... Not sure what to do with that. It is hard to defend a method if you don't know what the charges are!

    Like I said, I have been using it for years across three different versions without issues. Not saying that there aren't some obscure circumstances in which it might not work as expected, I just haven't come across any, though. Of course, we can't discount user error. Anything can have issues if it is not used correctly too!

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

Similar Threads

  1. Left Join not
    By j_a_monk in forum Queries
    Replies: 5
    Last Post: 08-07-2011, 09:47 AM
  2. Replies: 1
    Last Post: 07-25-2011, 09:57 AM
  3. inner, left or right join ?
    By toqilula in forum Access
    Replies: 0
    Last Post: 04-11-2011, 12:20 AM
  4. Replies: 3
    Last Post: 02-02-2011, 01:00 PM
  5. Update with LEFT JOIN
    By mcarthey in forum Access
    Replies: 1
    Last Post: 08-27-2008, 10:49 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