0

I know this is right:

select * from GoodmanLeads where Lastname is null

I know this is wrong:

select * from GoodmanLeads where Lastname = null

But it doesn't complain. Doesn't give a syntax error. Just doesn't produce any rows.

Does it have some meaning in t-sql that maybe many people don't know about?

Allied Stack
  • 69
  • 1
  • 10
  • If you wade through the syntax for an [expression](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/expressions-transact-sql?view=sql-server-ver15) you'll find it is allowed because _column binary_operator constant_ is allowed and `NULL` is about as good a constant as any. The semantics aren't very useful, as you've found, but many times I've added `and 1 = 0` as a way to disable some bit of code. – HABO Nov 05 '20 at 04:38

2 Answers2

0

null is kind of undefined/unknown value, so you can't really compare undefined to undefined. IS in this case will handle this specially, where as the = will be treated like a regular equality comparison.

AD.Net
  • 13,352
  • 2
  • 28
  • 47
0

Null is something unknown, not 0. so, something unknown is never equal to something else unknown value. simply Null is not equal to Null. so that the Lastname = null returns false always

umair
  • 525
  • 5
  • 18