Precedence in math

  • Thank you Ron. I don't mind an easy question once in a while. Besides, I'm just paranoid enough to have looked it over an extra time to see if I was missing something. There's value in that too. 🙂

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • BODMAS 🙂

    currently 7 wrong answers...

  • Wow, only 98% correct so far!

  • Nice attempt at the question, however I think this one is flawed

    Seeing how result two does not need the parentheses that is

    SELECT @a + (@B-@C) AS 'Result #2'

    is the same as

    SELECT @a + @B-@C AS 'Result #2'

    And there is only one answer with 1 as the second option. The user can guess at the answer without understanding the concept

    I would have thought

    SELECT @a + @b-2 * @C AS 'Result #4'

    would have been more challenging without the parentheses for most people.

  • BODMAS 🙂

    Edit: Shucks... Toreador, beat me to it.

    OK PEMDAS 😀


    Wayne

    Did you get access denied? Great the security works.

  • This one was easy by process of elimination, as Query 1 and Query 2 both return a 1 (addition/subtraction have same precedence, the parenthesis are superfluous) which yields the only right answer without looking at the queries that actually require precedence analysis.

    Nice easy question. I hope you have more on Precedence!

  • Toreador (1/10/2013)


    BODMAS 🙂

    currently 7 wrong answers...

    I'm alwasy surprised how many posts like this QOTD I've seen elsewhere where people proudly state BODMAS and then manage to come up with the wrong answer. I think there's a common misconception that each letter of the acronym is a higher priority than the next, instead of being pairs of operations.

  • sestell1 (1/10/2013)


    Toreador (1/10/2013)I think there's a common misconception that each letter of the acronym is a higher priority than the next, instead of being pairs of operations.

    That's true, but if you start at the left and work rightwards you'll always get the correct answer

  • SQLRNNR (1/9/2013)


    I completely disagree.

    Only for the sake of creating discord, malcontent, and to be argumentative because there is nothing in the question to whine about otherwise.

    How about the 2% who got it wrong? 🙂



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • mbova407 (1/10/2013)


    I would have thought

    SELECT @a + @b-2 * @C AS 'Result #4'

    would have been more challenging without the parentheses for most people.

    But then it would have been one of those questions going around on Facebook these days. 🙂



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • SQLRNNR (1/9/2013)


    I completely disagree.

    Only for the sake of creating discord, malcontent, and to be argumentative because there is nothing in the question to whine about otherwise.

    Thanks - so use to getting lots of discord, malcontent and whines that I was beginning to think that I just might have turned over a new leaf so to speak - horrors loosing my reputation !!

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Toreador (1/10/2013)


    sestell1 (1/10/2013)


    Toreador (1/10/2013)I think there's a common misconception that each letter of the acronym is a higher priority than the next, instead of being pairs of operations.

    That's true, but if you start at the left and work rightwards you'll always get the correct answer

    If you are talking about moving left to right in BODMAS, you will not get the correct answer. Take for instance 4 - 2 + 2.

    Moving left to write across the BODMAS acronym, addition comes before subtraction so the result is 0, when the correct answer should be 4.

  • Sometimes I answer these questions simply to get easy access to a link to their discussion.

    I was hoping for more discussion on why this was a QotD. I agree we should have basic math skills, possibly as prerequisite to basic SQL skills. I expected that this question was about to highlight a gotcha between math rules and SQL implementation. I also thought there should have been more answers so I couldn't have guessed correctly after result #2.

    Would there have been a gotcha using power() in this example? I discovered (the hard way) that power() returns int*. We use an alphanumeric key that is expanded to bigint using power( base, stringposition). It worked perfectly until the first bad-data supplied a string position (7) that exponentiated on the base (33) exceeded the int capacity of the power() function. Fortunately, this was done inside a UDF and I was able to replace the power() function with a case statement with literal values for each of the possible string length powers of our base.

    * yes, I know it's in BOL - but I only cared (after the fact) about that detail to explain why it failed 🙂

  • nice to recall everything... easy one....:cool:

    Manik
    You cannot get to the top by sitting on your bottom.

  • sestell1 (1/10/2013)


    Toreador (1/10/2013)


    If you are talking about moving left to right in BODMAS, you will not get the correct answer. Take for instance 4 - 2 + 2.

    Moving left to write across the BODMAS acronym, addition comes before subtraction so the result is 0, when the correct answer should be 4.

    just testing 😉

Viewing 15 posts - 16 through 30 (of 58 total)

You must be logged in to reply to this topic. Login to reply