March 1, 2012 at 8:24 am
I don't need to repeat how the actual explanation is incorrect, as this has been pointed out already. But I don't think anyone has covered what will happen in case of a type mismatch between the operand before the IN and (one of) the operands inside the IN.
In such a case, the operand with lower data type precedence will be implicitly converted to the higher predence. If that's successful, the query returns the expected result. If not, it will fail with a runtime error.
March 1, 2012 at 8:45 am
Thanks for the question, made me think and research for a while.
To me the explanation was clear. When stating
s.Statuses NOT IN (null, 'Idle')
you are trying to compare a data column attribute/property (null) against the actual value of the column, which returns UNKNOWN. Thus, UNKNOWN not being True (neither False), it will not set any row as selectable to return to the SELECT statement.
Thanks,
"El" Jerry.
March 1, 2012 at 8:53 am
Dang it. Should have thought about this one a little more. Good question.
March 1, 2012 at 9:52 am
interesting question.
Thanks
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 1, 2012 at 12:14 pm
good question. dealt with that issue in some code on Monday! :w00t:
Cheers
March 1, 2012 at 3:14 pm
I really enjoyed this one. Thanks!
March 1, 2012 at 7:16 pm
Stuart Davies (3/1/2012)
Good question - it reminds me why I do not like nulls
+1
Thanks
March 1, 2012 at 9:13 pm
tilew-948340 (3/1/2012)
Stuart Davies (3/1/2012)
Good question - it reminds me why I do not like nulls+1
Thanks
+1 ... Thanks 🙂
Thanks
March 5, 2012 at 12:31 am
Great question, thanks!
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 5, 2012 at 3:55 am
very good question!!!!
thanks!!!!
March 5, 2012 at 7:46 am
I got this right b/c of a great article I've kept bookmarked, "Ten Common SQL Programming Mistakes":
http://www.simple-talk.com/content/print.aspx?article=783
Ratchev lists it as item #1, with a straightforward, lucid explanation as to why the query fails, giving a few different T-SQL approaches to correctly query NOT IN for nullable columns.
Thanks,
Rich
March 12, 2012 at 6:39 am
Thank you for the question. It made me realize that NOT IN (x, y) really means NOT IN x AND NOT IN y.
I was thinking more like NOT IN x OR NOT IN y.
March 14, 2012 at 8:00 pm
Tough question. Thanks for submitting.
http://brittcluff.blogspot.com/
March 16, 2012 at 6:33 am
You have made a mistake in the correct answer!! The 'not in' was not referring to id. 5 points to me.
Viewing 15 posts - 31 through 45 (of 48 total)
You must be logged in to reply to this topic. Login to reply