Three-Valued-Logic , I've been using SQL for over ...
# random
v
Three-Valued-Logic , I've been using SQL for over 10 years and somehow never needed to know about this until today
obviously not using it enough! 😄
Copy code
Declare @a varchar = NULL
  Declare @b varchar = '1'
  Select IIF(@a = @b, 'TRUE', 'FALSE') --Evals to False
  Select IIF(NOT(@a = @b), 'TRUE', 'FALSE') -- False again, quay?
Spent way too long on this! Ends up being that I don't understand that SQL doesn't return just True and False. It also returns Unknown. https://modern-sql.com/concept/three-valued-logic Oh wow I had no clue
e
Oh interesting! I have had to use the
IS [NOT] DISTINCT FROM
before because of this issue, but I never thought more about than "because you can't use equality with nulls". Good read!
v
Nice! I'm glad you remember the "can't do equality with nulls part" I somehow didn't. With MSSQL there's no
IS DISTINCT FROM
so you get https://stackoverflow.com/questions/10416789/how-to-rewrite-is-distinct-from-and-is-not-distinct-from