I've had an unexpected outcome in a query that points to a subtlety that I'm probably not fully understanding.
I have a query like:
SELECT a.This, a.That, a.Another FROM tableA a WHERE a.Other <> 'Y'
a.Other is intended to operate as a Y/N flag column, but it also allows NULL values, which is way beyond my control (large commercial product).
I would expect that snippet to return all 'N' and NULL rows, but it is only returning rows with 'N'. If that column were set to NOT NULL, that wouldn't be an issue, but alas.
I'm getting the results desired by switching up that WHERE to
WHERE (a.Other IS NULL OR a.Other = 'N')
but why is the <> 'Y' excluding the NULL values? I've also phrased it using NOT IN ('Y'), and I still only get the 'N' values.
Can someone explain the reason behind that?
Data is stored on: Microsoft SQL Server 2017 (RTM-CU27) (KB5006944) - 14.0.3421.10 (X64)