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

Question of the Day for 23 May 2007 Expand / Collapse
Author
Message
Posted Tuesday, May 22, 2007 8:05 AM
SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, May 18, 2007 3:36 PM
Points: 10,039, 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.
Post #367941
Posted Wednesday, May 23, 2007 7:07 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, June 18, 2007 7:32 AM
Points: 177, Visits: 1
Is BOL wrong?  Query Analyzer returns NULL.
Post #368252
Posted Wednesday, May 23, 2007 8:30 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, June 8, 2011 8:07 AM
Points: 26, 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?

Post #368291
Posted Wednesday, May 23, 2007 8:47 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 10:37 AM
Points: 31,363, Visits: 15,826
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
Post #368306
Posted Wednesday, May 23, 2007 9:00 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, September 17, 2007 8:44 AM
Points: 330, Visits: 1
Does the same return for True?  i.e., if exp1 evaluates to True does it return true?


Post #368312
Posted Wednesday, May 23, 2007 11:00 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 2:16 AM
Points: 860, Visits: 812
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
Post #368344
Posted Wednesday, May 23, 2007 12:47 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 17, 2010 10:50 AM
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).

Post #368384
Posted Wednesday, May 23, 2007 12:56 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 17, 2010 10:50 AM
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. =)

Post #368387
Posted Wednesday, May 23, 2007 9:07 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 10:37 AM
Points: 31,363, Visits: 15,826
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
Post #368510
Posted Friday, May 25, 2007 4:11 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, January 4, 2012 3:37 AM
Points: 52, Visits: 37
UNKNOWN and FALSE should give UNKNOWN as is with any data with null gives null.
Post #368952
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse