Query not retrieving null fields

G

Guest

Hi,

I have a simple query in access.
Here is the SQL:
SELECT Table1.[Field]
FROM Table1
WHERE ((Not (Table1.[Field])="Y"));

In the field column, there are only rows of Y and null fields.
I want to select only the null fields, but when choosing the criteria not
"Y", it does not return any rows.
The datatype is Text and field size is 1.
I have tried using a different field size and it still doesn't work.
If I choose to select Null fields then the query works.

Any idea why it doesn't work if I choose not Y in the criteria (therefore
wanting to list null fields by default).

Hope this makes sense.

Thanks for your help.
 
B

Brendan Reynolds

Your expression will return rows where the result of the expression is True.
But the result of a comparison with Null is Null. Null represents an unknown
value. Is an unknown value equal to or not equal to 'Y' (or any other known
or unknown value)? The answer is unknown, i.e. Null.

To select only rows with Null values in the field, change the criteria to
....

WHERE Table1.Field Is Null
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top