Solved

MS Access Query  - Help with <> in query

Posted on 2014-07-27
2
299 Views
Last Modified: 2014-07-27
I have data that looks like this (simplified):

ID, Category
1,AB
2,CD
3,       <-- Blank or Null
4,EF
5,GH
6,AB
... 

Open in new window


When I try to filter out "GH" the query is also ignoring the Blank or Null rows. Here is the query:
SELECT ID, CATAGORY
FROM TestTable
WHERE CATAGORY <> "GH";

Open in new window


I have also tried this with the same results:
SELECT ID, CATAGORY
FROM TestTable
WHERE Not(CATAGORY = "GH");

Open in new window


I am at a loss why the results include all Categories except for "GH" (expected) and blank or null rows. This is omitting several thousand records that should be part of the results.
0
Comment
Question by:ckelsoe
2 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 40223200
It is a "normal" behaviour that applies to most databases. I could not find any "official" source from MSDN that is applicable to MS Access, here is a technical note applicable to SQL Server
There are two ways to fix this:
You can use a Nz function, like this:
SELECT ID, CATAGORY
FROM TestTable
WHERE Nz(CATAGORY, "") <> "GH";

Open in new window

Or you can add a condition for IsNull()
SELECT ID, CATAGORY
FROM TestTable
WHERE CATAGORY <> "GH" Or IsNull(CATEGORY);

Open in new window

0
 

Author Closing Comment

by:ckelsoe
ID: 40223445
Thanks - I forgot that. Query works as intended now.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now