Results 1 to 4 of 4
  1. #1
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138

    Query to ignore records where both fields are null


    I have been looking through the forums for a solution. I have tried various forms of the following:

    Code:
    SELECT WorkOrderNo, QualityNo FROM RCAData1 WHERE NOT WorkOrderNo ="" And QualityNo ="" ORDER BY RCAData1.WorkOrderNo;
    My problem is that I need to ignore the record if both are "" or both are null or possibly one of each.
    The synatx for this has my head pounding. Or maybe it is from banging it on the table.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    I don't allow empty strings in tables.

    SELECT WorkOrderNo, QualityNo FROM RCAData1 WHERE WorkOrderNo Not Is Null AND QualityNo Not Is Null ORDER BY WorkOrderNo;

    If there is possibility of either empty string or Null:

    SELECT WorkOrderNo, QualityNo FROM RCAData1 WHERE Nz(WorkOrderNo,"")<>"" AND Nz(QualityNo,"")<>"" ORDER BY WorkOrderNo;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138
    Funny thing, I copied it into my code and I got "Syntax error missing operator in query expression 'Nz(WorkOrderNo,")<> AND Nz(QualityNo,")<> "ORDER BY WorkOrderNo;'.

    The funny part is that if I paste it in the SQL view, it works perfect. Ideas.

    The I got it. Stupid me forgot to replace the "" with '', as it is defined in a string. Works great!!! Thanks for the help.

    For future reference, what is Nz?
    Last edited by dccjr; 05-10-2013 at 07:48 PM. Reason: Problem solved.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Nz is an intrinsic Access/VBA function. Use it to supply an alternative value if field is Null. In this case, I converted Null to empty string.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 7
    Last Post: 05-23-2012, 02:19 PM
  2. Search to ignore null fields
    By tommy93 in forum Queries
    Replies: 10
    Last Post: 02-07-2012, 10:58 AM
  3. Query Not Returning Null Fields
    By mgmirvine in forum Queries
    Replies: 2
    Last Post: 10-28-2011, 06:15 PM
  4. saving records without null or empty fields
    By amber mara in forum Access
    Replies: 1
    Last Post: 05-05-2010, 02:34 PM
  5. On Click - Ignore Required Fields
    By amy in forum Forms
    Replies: 1
    Last Post: 08-18-2009, 07:42 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