|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 7:32 AM
Points: 1,059,
Visits: 1,396
|
|
F1Droid (5/26/2010) Good question that in its simplicity makes you question what seems the obvious answer and think about it more deeply.
According to SQL Books Online, the parser actually checks all conditions and returns the first true condition, if none then returns "else" if its coded otherwise NULL. That's how it seems to be described.
Yeah, I had the right answer in 5 seconds, but took another 3 minutes to answer the question because I was sure it couldn't be that simple...
As for the Books Online reference, anyone know of a good way to introduce a condition with side-effects so we could verify if it does indeed check all conditions?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 8:36 AM
Points: 2,681,
Visits: 2,423
|
|
| I was thinking it has to be true, but wait....... So I spent a few more minutes thinking, only to come to the same conclusion.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 27, 2013 6:58 PM
Points: 16,
Visits: 35
|
|
The BOL seems to imply the 1 in "CASE 1" might be interpreted as a bit constant. Is this true? It seems 0/1 values are bit constants.
Note: It would not change the answer in this case due to the implicit conversion, but like others I was mistrusting and looking at it from all different angles. Just curious from an understanding standpoint.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Saturday, May 07, 2011 10:57 AM
Points: 3,
Visits: 9
|
|
| Thanks for explaining the example clearly. I answered it correctly but through some different logic. after your explaination, I understand my mistake
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Yesterday @ 6:02 AM
Points: 738,
Visits: 1,147
|
|
The question was pretty simple.....! But I really liked it.
Since the @flg is defined with value = 1 and it is matching 1 again in Case statement so result should be obviously 'true'.
Nice question...keep posting more question.... :) {{{{
Declare @flg as int
SEt @flg = 1
select case 1 when @flg then 'true'
when @flg then 'false' else 'noflg'
}}}} end as flag
Thanks.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 9:45 AM
Points: 2,163,
Visits: 2,151
|
|
Good question, thanks!
I'm actually a little surprised that most people got it correct.
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Saturday, April 06, 2013 12:20 AM
Points: 649,
Visits: 263
|
|
|
|
|