September 9, 2014 at 12:41 pm
Hello,
Please see screenshot attached. Why it is skipping NULL Value in query-2?
I want that NULL so I wrote query-3, is that correct?
Please reply. Thanks.
September 9, 2014 at 12:45 pm
dallas13 (9/9/2014)
Hello,Please see screenshot attached. Why it is skipping NULL Value in query-2?
I want that NULL so I wrote query-3, is that correct?
Please reply. Thanks.
Yes if you want to include NULL you need to do it like that. If you say Where MyColumn <> 3 it will exclude NULL because any type of equality check with a NULL results in NULL. As a result if your column has NULL it indeterminate if that row = 3 or <> 3 because the value is unknown.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 9, 2014 at 12:45 pm
I'm a noob but Predicates only evaluate to TRUE. Also NULL is not a value. Query 3 is correct as far as my very limited knowledge goes.
So it skips in query 2 because since NULL is not a value it cant be evaluated to true. It is thus evaluated to false as it is a unknown.
***SQL born on date Spring 2013:-)
September 9, 2014 at 12:59 pm
Thanks for the explanation guys.
September 9, 2014 at 3:14 pm
thomashohner (9/9/2014)
I'm a noob but Predicates only evaluate to TRUE. Also NULL is not a value. Query 3 is correct as far as my very limited knowledge goes.So it skips in query 2 because since NULL is not a value it cant be evaluated to true. It is thus evaluated to false as it is a unknown.
The first part is quite right: a condition in SQL must be true to be considered met, not simply "not false".
But the second part, be careful -- it's not evaluated to "false", it's evaluated to NULL also: effectively "unknown", since SQL can't determine if it's true or false.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
September 9, 2014 at 3:15 pm
I saw that very bad wording on my part.
***SQL born on date Spring 2013:-)
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply