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