Log in  ::  Register  ::  Not logged in

 Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Output of Query Rate Topic Display Mode Topic Options
Author
 Message
 Posted Thursday, October 28, 2010 6:47 AM
 SSCrazy Group: General Forum Members Last Login: Saturday, September 17, 2016 8:01 AM Points: 2,834, Visits: 2,629
 Regular reiteration of how nulls behave is very useful in QoTD. Thanks.
Post #1012266
 Posted Thursday, October 28, 2010 9:48 AM
 SSCrazy Group: General Forum Members Last Login: Tuesday, June 30, 2015 9:47 AM Points: 2,160, Visits: 2,204
 Thanks for the question!
Post #1012435
 Posted Thursday, October 28, 2010 12:58 PM
 Ten Centuries Group: General Forum Members Last Login: Thursday, January 31, 2013 8:01 AM Points: 1,228, Visits: 1,046
 Hugo Kornelis (10/28/2010)Good question, but a small (yet significan) mistake in the explanation.NULL does not represent the value 'UNKNOWN'.Hugo, perhaps you could ask M\$ to update the books online to match your opinion?When SET ANSI_NULLS is ON, a comparison in which one or more of the expressions is NULL does not yield either TRUE or FALSE; it yields UNKNOWN. This is because a value that is unknown cannot be compared logically against any other value. This occurs if either an expression is compared to the literal NULL, or if two expressions are compared and one of them evaluates to NULL. For example, the following comparison always yields UNKNOWN when ANSI_NULLS is ON:Copyytd_sales > NULLThe following comparison also yields UNKNOWN any time the variable contains the value NULL:ytd_sales > @MyVariableYoure comment is correct with one small but significant correction.When ANSI_NULLS is OFF NULL is not value UNKNOWN.
Post #1012594
 Posted Thursday, October 28, 2010 1:04 PM
 Ten Centuries Group: General Forum Members Last Login: Thursday, January 31, 2013 8:01 AM Points: 1,228, Visits: 1,046
 Great question Sunil. Good example of how NULLS are counted in a column of data.I also give this question 5 stars for having no typos or confusion in the code, question, or answers!
Post #1012596
 Posted Thursday, October 28, 2010 3:05 PM
 SSCertifiable Group: General Forum Members Last Login: Yesterday @ 9:30 AM Points: 7,765, Visits: 11,375
 SanDroid (10/28/2010)Hugo Kornelis (10/28/2010)Good question, but a small (yet significan) mistake in the explanation.NULL does not represent the value 'UNKNOWN'.Hugo, perhaps you could ask M\$ to update the books online to match your opinion?When SET ANSI_NULLS is ON, a comparison in which one or more of the expressions is NULL does not yield either TRUE or FALSE; it yields UNKNOWN. This is because a value that is unknown cannot be compared logically against any other value. This occurs if either an expression is compared to the literal NULL, or if two expressions are compared and one of them evaluates to NULL. For example, the following comparison always yields UNKNOWN when ANSI_NULLS is ON:Copyytd_sales > NULLThe following comparison also yields UNKNOWN any time the variable contains the value NULL:ytd_sales > @MyVariableI wrote that NULL does not represent unknown. I also wrote that a comparison to NULL does result in the truth value Unknown.You quote an excerpt from BOL that states that comparisons in which one or more of the operands are NULL yield Unknown. I fail to see the mismatch between the BOL quote and my post.That being said, BOL does contain lots of errors - it is an excellent reference for the product SQL Server, but it is far from perfect when it comes to relational theory.Youre comment is correct with one small but significant correction.When ANSI_NULLS is OFF NULL is not value UNKNOWN.I already admitted in a previous post that I never use ANSI_NULLS off. (And that no one should, really) Hugo Kornelis, SQL Server MVPVisit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1012668
 Posted Thursday, October 28, 2010 3:23 PM
 Ten Centuries Group: General Forum Members Last Login: Thursday, January 31, 2013 8:01 AM Points: 1,228, Visits: 1,046
 Hugo Kornelis (10/28/2010)[quote]I wrote that NULL does not represent unknown.I understand that is what you wrote. I thought maybe you would look at the referenced article before responding.Let me grab another cut and paste of the BOL that was referenced for the question."The value NULL means the data value for the column is unknown or not available."That is the very first sentance from the Books online: http://msdn.microsoft.com/en-us/library/ms191270%28v=SQL.100%29.aspx Now I understand that the Books Online have often been wrong.Do you believe they are in this instance?
Post #1012681
 Posted Thursday, October 28, 2010 4:21 PM
 SSCertifiable Group: General Forum Members Last Login: Yesterday @ 9:30 AM Points: 7,765, Visits: 11,375
 SanDroid (10/28/2010)Hugo Kornelis (10/28/2010)[quote]I wrote that NULL does not represent unknown.I understand that is what you wrote. I thought maybe you would look at the referenced article before responding.Since you didn't provide a reference and didn't indicate in any way that you wanted me to comment on the part you didn't quote, I could only assume that the quoted text was what you wanted me to comment on.Let me grab another cut and paste of the BOL that was referenced for the question."The value NULL means the data value for the column is unknown or not available."That is the very first sentance from the Books online: http://msdn.microsoft.com/en-us/library/ms191270%28v=SQL.100%29.aspx Now I understand that the Books Online have often been wrong.Do you believe they are in this instance?Thanks for the reference. I have now read the entire article.I qualify it as sloppy, not as wrong. The first line you quote above is "sort of" correct. Since NULL represents missing data, "not available" is spot-on. The additional "unknown" in that sentence is superfluous, a bit like describing someone as "New Yorker or American" - unknown is a subset of missing value, as New Yorker is a subset of American.In the paragraph on camparing NULL values, I find this sentence, as an explanation of why NULL comparisons yield UNKNOWN:"This is because a value that is unknown cannot be compared logically against any other value."The "value is unknown" here is the old incorrect interpretation of NULL. But after the introductory paragraph above, this is easily identified as a sloppy reference, and it won't be taken as a change to the previous explanation.This kind of sloppiness annoys me. But I count my blessings - I've seen BOL pages that were much, much worse than this one. Hugo Kornelis, SQL Server MVPVisit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1012731
 Posted Tuesday, November 2, 2010 2:28 PM
 SSC-Insane Group: General Forum Members Last Login: Monday, November 21, 2016 11:03 AM Points: 20,009, Visits: 18,255
 Thanks for the question. Jason AKA CirqueDeSQLeilI have given a name to my pain...MCM SQL Server, MVPSQL RNNRPosting Performance Based Questions - Gail Shaw
Post #1014891
 Posted Tuesday, November 9, 2010 12:24 AM
 SSCrazy Group: General Forum Members Last Login: Tuesday, July 19, 2016 4:34 AM Points: 2,850, Visits: 4,076
 Thanks to OP and special thanks to HUGO for great explanation. -------Bhuvnesh----------I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1017637
 Posted Tuesday, December 21, 2010 2:42 AM
 Forum Newbie Group: General Forum Members Last Login: Monday, July 18, 2011 3:38 AM Points: 2, Visits: 5
 Um, NO! You have inverted the condition on the <> '1' to = '1' with this "IN" statement.
Post #1037583

 Permissions

 Copyright © 2002-2016 Redgate. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.