SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Question of the Day for 23 May 2007


Question of the Day for 23 May 2007

Author
Message
Site Owners
Site Owners
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: Administrators
Points: 12661 Visits: 16
Comments posted to this topic are about the Question of the Day for 23 May 2007 posted at http://www.sqlservercentral.com/testcenter/qod.asp?QuestionID=1046.
John Lento
John Lento
SSC-Enthusiastic
SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)

Group: General Forum Members
Points: 177 Visits: 1
Is BOL wrong? Query Analyzer returns NULL.
carie dobson
carie dobson
SSC Journeyman
SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)

Group: General Forum Members
Points: 78 Visits: 39

I'm confused. The BOL & referenced link shows:

UNKNOWNUNKNOWNFALSEUNKNOWN

To me this says that if you combine False & Unknown you get Unknown. How can it mean it returns false?

Does anyone have an example?


Steve Jones
Steve Jones
SSC Guru
SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)

Group: Administrators
Points: 145429 Visits: 19425
AND evaluates two expressions.

(exp 1) and (exp 2)

If exp1 evaluates to false, it doesn't matter if exp 2 is true, false, or unknown. The entire expression is false. It's basic logic.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Steve Fine
Steve Fine
Mr or Mrs. 500
Mr or Mrs. 500 (506 reputation)Mr or Mrs. 500 (506 reputation)Mr or Mrs. 500 (506 reputation)Mr or Mrs. 500 (506 reputation)Mr or Mrs. 500 (506 reputation)Mr or Mrs. 500 (506 reputation)Mr or Mrs. 500 (506 reputation)Mr or Mrs. 500 (506 reputation)

Group: General Forum Members
Points: 506 Visits: 2
Does the same return for True? i.e., if exp1 evaluates to True does it return true?



Stephen E. Cook
Stephen E. Cook
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1063 Visits: 818
DECLARE @a INT, @b INT
SET @a = 0
SELECT CASE WHEN (@a = 1 /*FALSE*/ AND @b = 1 /*UNKNOWN*/) THEN 'FALSE' ELSE 'UNKNOWN' END

I thought this was a SQL Server question, not a basic logic question

-- Stephen Cook
Dan White-276279
Dan White-276279
SSC Veteran
SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)

Group: General Forum Members
Points: 279 Visits: 48

You need to look at the header of the table also. UNKNOWN (in bold on the left) is being compared to 3 different values in the top row. The intersection of the row and the column give the result.

TRUE FALSE UNKNOWN

TRUE

TRUE

FALSE

UNKNOWN

FALSE

FALSE

FALSE

FALSE

UNKNOWN

UNKNOWN

FALSE

UNKNOWN

When UNKNOWN is compared to FALSE with the AND operator, the result is FALSE (in red).


Dan White-276279
Dan White-276279
SSC Veteran
SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)SSC Veteran (279 reputation)

Group: General Forum Members
Points: 279 Visits: 48

Stephen,

Your CASE statement results might more accurately be given as

DECLARE @a INT, @b INT
SET @a = 0
SELECT CASE WHEN (@a = 1 /*FALSE*/ AND @b = 1 /*UNKNOWN*/) THEN 'TRUE' ELSE 'NOT TRUE' END

The statement shows that the result of the AND operation is NOT TRUE, but it does not tell you whether it is FALSE or UNKNOWN. That's where basic logic is important in order to understand SQL Server results. =)


Steve Jones
Steve Jones
SSC Guru
SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)

Group: Administrators
Points: 145429 Visits: 19425
For TRUE, you need (TRUE) and (TRUE). (TRUE) and (Unknown) means you don't know if you have 2 trues or one of each, so the answer is Unknown.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Girish Sumaria
Girish Sumaria
Valued Member
Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)

Group: General Forum Members
Points: 74 Visits: 37
UNKNOWN and FALSE should give UNKNOWN as is with any data with null gives null.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search