Solved

MS Access Query  - Help with <> in query

Posted on 2014-07-27
2
293 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Spell checking an unbound form in MS Access 2013 9 40
SQL query 4 31
formattig excel from access 3 18
sql query Help 12 34
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

746 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

13 Experts available now in Live!

Get 1:1 Help Now