I have a table with one column named value, of type int, and 4 rows in it:
20
50
NULL
0
Why does this query return 20 and 50 only? I need NULL values, too.
SELECT *
FROM dbo.myTable
WHERE value != 0
In SQL, NULL
is a special value, nothing can ever be equal to or not equal to it. In fact, NULL
doesn't even equal itself. When searching for null values, you must use the IS
operator. So you need to change your query to include them:
SELECT *
FROM dbo.myTable
WHERE value !=0
OR value IS NULL
You can also replace null for sth else what is not a zero using isnull
or coalesce
SELECT *
FROM dbo.myTable
WHERE ISNULL(value,1) <> 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With