Does not equal operator and is null question
Posted on 2007-10-11
I have a SQL statement that does a count and has this in the where statement... my question is, why do I have to add the person_status_code is null to get the correct count? I would have thought that person_status_code <> 'D' would have returned everything, including null values since they don't equal 'D'... but to get the correct count I also had to include the or person_status_code is null. Can someone give me the reason why it behaves like this? Below is the SQL statement in question that I'm refering to.
select count(distinct person_id) as person_count from person where primary_source_code in ('A', 'PU') and (person.person_status_code <> 'D' or person.person_status_code is null)"