I just realized very strange behavior of my MsSql database when filtering empty string != ''
or <> ''
regarding NULL values.
I have following data in the table
ID | Value | (table X) |
---|---|---|
1 | (empty string) | |
2 | NULL | (no value) |
3 | text | (some real text) |
This query select * from X where Value = ''
results in:
- ID: [1]
Both queries select * from X where Value != ''
and select * from X where Value <> ''
result in:
- ID: [3]
What I do not understand is, why 2nd query is not returning ID=2?
I know the syntax for checking explicitly on null values where Value IS NULL
so I would expect, that 2nd query would behave differently. When checking for non-empty values, I used to write where Value <> '' AND Value IS NOT NULL
. From now on I am totally confused...