Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Query Results when Nulls are involved

Status
Not open for further replies.

ebrooks54

IS-IT--Management
Dec 4, 2002
54
0
0
US
I haven't noticed this behaviour before, and it really has me scratching my head...

Using Access 2003

I have a table with 12,104 records in it. A query with no criteria returns 12,104 rows.

A query with Message Type = 'TMSG' returns 1,312 rows.
A query with Message Type <> 'TMSG' returns 6,586 rows.

By inspection, the missing rows all contain NULL in the message type field. It appears that using the <> condition has forced the query to ignore any records where the field has no value.

Adding an OR criteria of Message Type IS NULL adds the missing rows to the results, but this does not appear 'normal' to me.

Am I doing something wrong?
 
Consider a Null value as UNKNOWN and then you'll understand the behaviour.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Simply stated, a null value is neither equal nor not equal to a value.

Rather than adding the or clause, you could use the NZ function:

...Message Type <> nz('TMSG', '')

or simply

...Message Type <> nz('TMSG')


Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
I try to always use Nz() with 2 arguments.

Me too; I was just trying to provide some options. [smile]

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top