Click here to monitor SSC
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 (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10093 Visits: 1
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 Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 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-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36148 Visits: 18751
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
Old Hand
Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)

Group: General Forum Members
Points: 330 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
SSC Eights!
SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)

Group: General Forum Members
Points: 863 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 (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)

Group: General Forum Members
Points: 271 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 (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)

Group: General Forum Members
Points: 271 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-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36148 Visits: 18751
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 (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 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