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
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 (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 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 (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)

Group: Administrators
Points: 61325 Visits: 19097
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 (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)

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

Group: General Forum Members
Points: 899 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 Guru
SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)

Group: Administrators
Points: 61325 Visits: 19097
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 (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 Visits: 37
UNKNOWN and FALSE should give UNKNOWN as is with any data with null gives null.
Steve Jones
Steve Jones
SSC Guru
SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)

Group: Administrators
Points: 61325 Visits: 19097
Girish, that is not the case in logical operations. With an AND, only one operand is required to be false to give false. So if one side is false, it doesn't matter if the other side is true or false, which are the two possible values for Unknown. It's unknown.

Just as with an OR. If one side is true, it does not matter if the other side is true.

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
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