select A from table1 where A <> '-'
This query excludes -
and also the null values. Why the null values?
select A from table1 where A <> '-'
This query excludes -
and also the null values. Why the null values?
<> is Standard SQL-92; != is its equivalent. Both evaluate for values, which NULL is not -- NULL is a placeholder to say there is the absence of a value.
Which is why you can only use IS NULL/IS NOT NULL as predicates for such situations.
This behavior is not specific to SQL Server. All standards-compliant SQL dialects work the same way.
See Reference Here:
Not equal <> != operator on NULL
Just look for the proper keywords for you to browse for results to your problem efficiently
NULL
values are always exluded if you don't include them explcitely via IS NULL
. NULL means not unknown. You can't select them with = NULL
or omit them with <> NULL
. Any comparison with NULL
results not in true
or false
but in unknown.
You have to use
SELECT A from table1 where A IS NULL OR A <> '-';
another way using COALESCE
:
SELECT A from table1 where COALESCE(A, '') <> '-';
Read: https://en.wikipedia.org/wiki/SQL#Null_or_three-valued_logic_.283VL.29