Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Output of Query Expand / Collapse
Author
Message
Posted Thursday, October 28, 2010 6:47 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 2:16 PM
Points: 2,812, Visits: 2,543
Regular reiteration of how nulls behave is very useful in QoTD. Thanks.
Post #1012266
Posted Thursday, October 28, 2010 9:48 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, March 27, 2014 8:50 AM
Points: 2,163, Visits: 2,184
Thanks for the question!
Post #1012435
Posted Thursday, October 28, 2010 12:58 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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.

Post #1012594
Posted Thursday, October 28, 2010 1:04 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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!


Post #1012596
Posted Thursday, October 28, 2010 3:05 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:05 PM
Points: 5,793, Visits: 8,002
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
Post #1012668
Posted Thursday, October 28, 2010 3:23 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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?
Post #1012681
Posted Thursday, October 28, 2010 4:21 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:05 PM
Points: 5,793, Visits: 8,002
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
Post #1012731
Posted Tuesday, November 02, 2010 2:28 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 8:11 PM
Points: 20,455, Visits: 14,075
Thanks for the question.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1014891
Posted Tuesday, November 09, 2010 12:24 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, March 14, 2014 2:19 AM
Points: 2,820, Visits: 3,916
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

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse