What will the results be for the code below?

  • Comments posted to this topic are about the item What will the results be for the code below?

  • Good question ...

    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]

  • Good Question. Explanation clears all the doubts

  • Good Question with Proper Explanation. Thank u

  • Good question and I learnt something ๐Ÿ™‚

    I wonder how many of those who got it right (70% at the moment) did so without running the script first!

  • Good Question & Nice Explanation. Thanks ๐Ÿ™‚

    Thanks

  • Nice question!

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Precedence, operation order, and implicit conversion. How many times have I been caught by those? Great explanation.

  • Great question and explanation. Reinforces the need to pay attention to detail.

    Steve Jimmo
    Sr DBA
    โ€œIf we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan

  • Thanks for the comments. This was my first QotD and I was worried that my explanation might not have been clear enough. (The formatting is certainly an issue, but I don't think we can't format much, if any, in the explanation. Though I swear I had line breaks in there.)

  • The good thing is that I learned somethng here, and not about conversion precedence.

    I answered that the intial assignment would fail as the CONVERT function seemed wrong. The third parameter, 101 in this case, is optional for converting strings to datetime but could be necessary to resolve ambiguities when some dates are presented in formats other than the db's local standard. I'd wrongly thought that the third parameter only worked for converting datetime TO a string.

  • Nice QOTD.

    I got it right but for different reasons. If you wanted to add an additional wrinkle try:

    SELECT @Var2 = ' - ', @Var3 = CONVERT(DATETIME, '01/01/2010', 101),@Var1 = cast(@var3+5 as int);

    SELECT @Var1 + @Var2 + @Var3 AS Result1;

    If the perception is that this is performing date addition (e.g. Dateadd) the above expected result would be 5, not 2120-01-07 00:00:00.00.

    Tim

  • A very good explantation - thanks. I got it right with a bit of guesswork, but hadn't realised that the operator precedence was the key.

  • Toreador (11/1/2010)


    Good question and I learnt something ๐Ÿ™‚

    I wonder how many of those who got it right (70% at the moment) did so without running the script first!

    I did ๐Ÿ˜€ .... I've got my share wrong too. :crying:

  • Hm, am I the only one who thinks the given answer is false?

    According to it, there will be a "type conversion". But instead there is only a "type conversion error". Two different things...

    Best Regards,

    Chris Bรผttner

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

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