Conversion

  • bc_

    Hall of Fame

    Points: 3099

    Comments posted to this topic are about the item Conversion

    [font="Arial Narrow"]bc[/font]

  • Marius Els

    Right there with Babe

    Points: 760

    My answer was correct but my reasoning for getting to the answer seemed to have been incorrect; I thought the error would be generated on printing integer and varchar variables together whereby a convert would be required for the int variable.

    But after reading the explanation to the answer and going through the msdn article, I learned something new. 🙂

  • HanShi

    SSC-Dedicated

    Points: 33239

    I thought putting the integer value 500000 into a varchar(5) would result in a string with value '50000' (removed last 0). Now I learned it's resulting in a string with value '*'.

    Thanks for letting me learn someting new...:w00t:

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • Marius Els

    Right there with Babe

    Points: 760

    HanShi (10/6/2008)


    I thought putting the integer value 500000 into a varchar(5) would result in a string with value '50000' (removed last 0). Now I learned it's resulting in a string with value '*'.

    Thanks for letting me learn someting new...:w00t:

    this was part of my thinking as well, that the value will just be truncated.....

    hence i moved on to the following steps and anticipated the error further down the statement list.

  • webrunner

    One Orange Chip

    Points: 29987

    Thanks, neat question.

    I'm sure this may not work every time, but I used the process of elimination based on the sums provided as answers.

    I first assumed that there was no error, and that @first would be 50000 (truncated due to varchar(5)).

    That led me to get @number + @first + @second = 500000 + 50000 + 50000 = 600000.

    600000 wasn't one of the sums given as an answer, so I figured I should pick the error as my answer. Had 600000 been an available answer choice, I probably would have picked it and gotten the answer wrong.

    Just my two cents if you want to make it tougher in the future to guess at the answers.

    webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and says Can I join you?
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • StarNamer

    SSCrazy Eights

    Points: 8633

    I got thius right because I'd seen this error before, but also think more people would not have picked up the error if 600000 had been offered as an answer, i.e. 500000+'50000'+'50000'.

    The other obvious wrong answer would be 500000, i.e. if you assume the truncation occurs to the right i.e. 500000 becomes '00000' (leading '5' dropped) and you then get 500000+'0'+'0'.

    I'd be interested to see what logic is supposed to arrive at either 15000 or 150000 since I can't see any obvious way to get either of these.

    Derek

  • Nikhil Shikarkhane

    Default port

    Points: 1478

    That was a good one...

  • bc_

    Hall of Fame

    Points: 3099

    i had a hard time coming up with false answers that would throw the reader off. i thought some might misread 50000 for 500000, and thus 150000 (50000+50000+50000). anyway this was my first attempt at writing a QOD. i hope a few people learned about this "gotcha" that puzzled me when i first came upon it in trying to answer another forum question. thanks

    [font="Arial Narrow"]bc[/font]

  • webrunner

    One Orange Chip

    Points: 29987

    bc (10/6/2008)


    i had a hard time coming up with false answers that would throw the reader off. i thought some might misread 50000 for 500000, and thus 150000 (50000+50000+50000). anyway this was my first attempt at writing a QOD. i hope a few people learned about this "gotcha" that puzzled me when i first came upon it in trying to answer another forum question. thanks

    Well, you did catch a few people - about 9% 🙂 - but if you had made one other choices 600000 (or 500000 as Derek suggests above), I'd say you would have caught closer to 25% combined with one of the wrong answers.

    Still, you made a great question. You should try posting more of them!

    webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and says Can I join you?
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • Marius Els

    Right there with Babe

    Points: 760

    agreed this was an insightful question, well done!

  • Preet_S

    SSCrazy

    Points: 2074

    Like many who attempted the question, I got the right answer but possibly for the wrong reason. At first, I though truncation and implicit conversion would occur, but as 600,000 was not offered as pointed out by others, it was a simple process of elimination.

    I shall have a read of BOL.

    Good ques.

  • StarNamer

    SSCrazy Eights

    Points: 8633

    bc (10/6/2008)


    i hope a few people learned about this "gotcha" that puzzled me when i first came upon it in trying to answer another forum question. thanks

    As I mentioned, I'd already encountered this before, but I too puzzled over it when I first saw it.

    Definitely a good question.

    Derek

  • kapil_kk

    SSC-Insane

    Points: 21316

    Good one!! 🙂

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 13 posts - 1 through 13 (of 13 total)

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