|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 1:10 PM
Points: 2,673,
Visits: 2,418
|
|
| Regular reiteration of how nulls behave is very useful in QoTD. Thanks.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,232,
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?
<Quote from BOL> 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 > NULL
The following comparison also yields UNKNOWN any time the variable contains the value NULL:
ytd_sales > @MyVariable
<Quote from BOL>
Youre comment is correct with one small but significant correction. When ANSI_NULLS is OFF NULL is not value UNKNOWN.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,232,
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!

|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:22 AM
Points: 5,244,
Visits: 7,059
|
|
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? <Quote from BOL> 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 > NULL The following comparison also yields UNKNOWN any time the variable contains the value NULL: ytd_sales > @MyVariable <Quote from BOL>
I 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 MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,232,
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?
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:22 AM
Points: 5,244,
Visits: 7,059
|
|
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 MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 20, 2013 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
|
|
|
|
|
|
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.
|
|
|
|