I have this SQL query in SQL Server for context.
SELECT
O.OrderID, SUM(P.Quantity) AS SprayGlueCans
FROM
FCMDB.dbo.FcoOrders O
JOIN
FCMDB.dbo.FcoStyleGroups SG ON SG.OrderID = O.OrderID
JOIN
FCMDB.dbo.FcoProducts P ON P.StyleGroupID = SG.StyleGroupID
WHERE
P.CatalogProductID = 12715
AND O.Shipped = 1
AND MONTH(O.ShipDate) = 8
AND YEAR(O.ShipDate) = 2023
AND O.InstallerID <> 3
AND InstallerID <> 29
GROUP BY
O.OrderID
When I run it everything works great except for the fact that the InstallerID
can be NULL. I expected this to not matter because. I was under the assumption that since NULL is not 3 or 29 then it would be included in the results. But this query seems to leave out everything with a NULL InstallerID
. I was wondering why this is so.
Is this just how it works? If so am I supposed to be careful to not write queries that have this mistake again? And if that is true are there practices or design choices to best handle or avoid this situation?