|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 3:48 AM
Points: 660,
Visits: 557
|
|
Very good question in my book.
All too often you get guys spending hours debugging code and scratching heads when all along it was just someone chuffed up a datatype previously.
The devil is in the details!
-------- I love deadlines. I like the whooshing sound they make as they fly by. -Douglas Adams
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
Rob Goddard (10/14/2009) Very good question in my book.
All too often you get guys spending hours debugging code and scratching heads when all along it was just someone chuffed up a datatype previously.
The devil is in the details!
I would agree except the question did not say, Why doesn't this produce the expected result of 56? It was not a troubleshooting question but a question about the operators AND and OR.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, July 22, 2011 4:13 AM
Points: 1,149,
Visits: 603
|
|
I agree with dave.farmer. This wasn't a SQL knowledge question but more of a practical joke
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 11:27 AM
Points: 1,407,
Visits: 2,020
|
|
Goodness! People are whiny today!
Jason Shadonix MCTS, SQL 2005
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 5:22 AM
Points: 1,037,
Visits: 1,354
|
|
Well, this question does provide one good bit of information.
Based on the answer %s at the time of of writing, I estimate than somewhere between 66% and 74%* of the respondents to the question simply copied the code into a query processor and ran it to get their answer.
Cheating, or simply using available resources?
* 74% answered correctly, and I'm willing to accept that ~10% of those actually saw the trick. I rounded up to give them the benefit of the doubt.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 1,356,
Visits: 4,761
|
|
archie flockhart (10/14/2009) Not only a trick question, but one that is possible to get right by getting the reasoning all wrong...
If you don't know that AND and OR operate bitwise on integers, you might assume that it works like Excel's AND() function which treats nonzero values as TRUE and zeroes as FALSE. Then it would return 1 as the value, even if all the variables were declared as INT.
So you'd get the right answer, but for the wrong reason - and you'd go away "knowing" something about these operators that "ain't so".
Exactly what I did 
Only I didn't go away "knowing" something, I came here and found out the truth
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, April 12, 2013 8:07 AM
Points: 183,
Visits: 194
|
|
I believe this to be a good question with a not so good title. I got a chance to review the bitwise operators, and the bit data type and I think that was helpful.
Also msdn.microsoft has the bit data type described as :
"An integer data type that can take a value of 1, 0, or NULL."
I think what they mean by "can take" is in question because we see that it will take a 56 and will translate it to a 1. I did a little excercise to see just what values you can use in an expression like "Select @bitVariable = ". It was interesting.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Friday, March 15, 2013 2:43 PM
Points: 3,924,
Visits: 1,554
|
|
Tricky question.
Looks like there is lots of disappointment in air today.
SQL DBA.
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 10:57 PM
Points: 1,491,
Visits: 3,008
|
|
Stop whining about "trick" questions! This one taught me to consider and be careful of automatic conversion of datatypes.
I got it right, but would have missed it if one of the choices were "0".
a = 120 = x'01111000' b = 30 = x'00011110' a & b = x'00011000' = 24 d = 40 = x'00101000' (a&b)|d = x'00111000' = 56 Since the result is being put to a "BIT" datatype, I mistakenly thought that the binary representation of the integer 56, x'111000', would be truncated to the last bit which is zero.
But the conversion of any non-zero numeric to type BIT yeilds value '1', so that's the correct answer.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 3:46 PM
Points: 354,
Visits: 170
|
|
If this question has taught us anything, it's how NOT to write declare statements.
I love binary artithmetic! Even hex to an extent, just for something different. And to have my morning fun ruined by poorly set out SQL... Yes, i know it saves space, but this isnt the 1980's anymore, bytes come by the billion (literally)!
|
|
|
|