문제

I am having an issue with filtering out phone numbers which have no value in them ie:

(___) ___ - ____

I tried this in my WHERE clause to get ALL the values that had a full phone number:

WHERE WRT_Phone <> null;

This allowed me to get all the phone numbers that had a full value in them. But, when I attempt

WHERE WRT_Phone = null;

Nothing gets populated in the resulting table. Are there any functions that I can use to turn the area code into a number or a function to check if phone number data type is null?

Also, I am using Access 2010 for executing the SQL statements.

도움이 되었습니까?

해결책

The syntax to check for nulls is:

WHERE WRT_Phone IS null;

다른 팁

To check for nulls you need to use IS NULL:

WHERE WRT_Phone IS NULL

In fact, to check for not null, you should technically use IS NOT NULL:

WHERE WRT_Phone IS NOT NULL

Something frankly odd (unique to Access?) is happening here because you should not be getting any results with WHERE WRT_Phone <> null either.


Generally speaking, when NULL is present on either side of a boolean operator or as part of an expression, the whole thing evaluates to NULL (which is considered FALSE for the purposes of a WHERE clause):

  • In a non-null record:
    • WRT_Phone = NULL expands to 'foobar' = NULL which equals NULL -> no record returned
    • WRT_Phone <> NULL expands to 'foobar' <> NULL which equals NULL -> no record returned
  • Likewise, in a null record:
    • WRT_Phone = NULL expands to NULL = NULL which equals NULL -> no record returned
    • WRT_Phone <> NULL expands to NULL <> NULL which equals NULL -> no record returned
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top