0

I am trying to count the number of missing postal codes using CASE to flag null values as 1, otherwise 0.

 CASE WHEN ([postcode]=NULL)
 THEN 1
 ELSE 0 END AS pc_missing

Even though I know there are lots of missing data, none of them receive the value of 1.

What have I done wrong?

user2964644
  • 189
  • 9

1 Answers1

0

null is not a value - it's the lack of a value. null returns "unknown" (which is not true) when evaluated against any value operator - =, !=, >, <, etc. Instead, you should check it with the is [not] null operator:

 CASE WHEN ([postcode] IS NULL)
 THEN 1
 ELSE 0 END AS pc_missing
Mureinik
  • 297,002
  • 52
  • 306
  • 350