# AND & OR

• Comments posted to this topic are about the item AND & OR

• Tricky question especially in the morning 😀

Kindest Regards,

Damian Widera
SQL Server MVP,
MCT, MCSE Data Platform, MCSD.NET

• arghh!! I spent a few minutes playing with a spreadsheet to mock up the bitwise AND and OR functions (a happy little diversion) and i missed the data type gotcha!

ah well...

Life: it twists and turns like a twisty turny thing

• I just did the same thing -- missed the bit datatype.

120 = 01111000

030 = 00011110

040 = 00101000

120 and 30 = 11000 in binary or 8 + 16 = 24

24 or 40 = 11000 or 101000 = 111000 = 8 + 16 + 32 = 56

Well, all that work was thrown out the window because of the bit datatype.

I'm getting tired of these trick questions. The title of the question says AND & OR and that led me to believe the author is testing our binary skills -- not our visual acuity. We have a list of variables that are all INT except one that's squeezed in the middle. Sheesh.

• I am disappointed with the question, too.

If I copied the script into SSMS, I would get the right answer. Instead, I took a piece of paper and wrote binary 'ones' and 'zeroes'... and didn't notice the 'bit' trick...

• I completely agree with this, though I was this time lucky I found the bit this time. But this is not testing for knowledge about the meaning of bitwise comparising, which can be very useful.

Ronald HensbergenHelp us, help yourself... Post data so we can read and use it: http://www.sqlservercentral.com/articles/Best+Practices/61537/-------------------------------------------------------------------------2+2=5 for significant large values of 2

• Absolutely ridiculous!

What is the point of a trick question on a technical forum?

Maybe you could argue that as developers we need to pay attention to the smallest detail, but that's a pretty thin argument when we're coming here to challenge our knowledge, not our powers of observation.

A question about AND and OR is good, working out the answer is a pleasant diversion, discovering that it wasn't a question about AND or OR at all but rather an exercise in hiding the word 'bit' amongst a list of 'int's and seeing who noticed... really disappointing, to the point of making me angry!

I'm sorry - I know people put effort into making up the questions and they could have a legitimate point that I have no right to complain when I don't submit questions of my own, but this is just annoying.

• hodgy (10/14/2009)

arghh!! I spent a few minutes playing with a spreadsheet to mock up the bitwise AND and OR functions (a happy little diversion) and i missed the data type gotcha!

ah well...

I hope you know about the Excel functions DEC2BIN and BIN2DEC (from Analysis Toolpak)...

Ronald HensbergenHelp us, help yourself... Post data so we can read and use it: http://www.sqlservercentral.com/articles/Best+Practices/61537/-------------------------------------------------------------------------2+2=5 for significant large values of 2

• vk-kirov (10/14/2009)

I am disappointed with the question, too.

If I copied the script into SSMS, I would get the right answer. Instead, I took a piece of paper and wrote binary 'ones' and 'zeroes'... and didn't notice the 'bit' trick...

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

• I think that was a nice question because it practices the capacity to get the details: sometimes, I make error (well it does not append that often :hehe:) and can look for them for a long time, missing the detail ...

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

--------
[font="Tahoma"]I love deadlines. I like the whooshing sound they make as they fly by. -Douglas Adams[/font]

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

• I agree with dave.farmer.

This wasn't a SQL knowledge question but more of a practical joke

• Goodness! People are whiny today!

The Redneck DBA

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

Viewing 15 posts - 1 through 15 (of 31 total)