This is something that has baffled me before but I have never found an explanation for it. I have a column in a SQL Server 2008 database that is of type smallint. I want to look for any rows where the value is NULL or blank, so I say this:
SELECT *
FROM products
WHERE warranty_dom IS NULL
OR warranty_dom = ''
This returns rows with a value of 0
So why is 0 treated as the equivalent of '' ?
0 is not treated as ” per se. Instead, ” is implicitly cast to an integer, and that cast makes it 0.
Try it yourself:
Also, as mentioned elsewhere: If warranty_dom is of type smallint, then it’s not possible for it to be blank in the first place.