Solved

MS Access Query  - Help with <> in query

Posted on 2014-07-27
2
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

717 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