The answer to life, the universe and prime numbers

  • Comments posted to this topic are about the item The answer to life, the universe and prime numbers

  • Nice question Eirikur. That was one of those where I knew the answer as soon as I saw the title but I still had to check because my Sci-Fi knowledge is much broader than my SQL Server knowledge and I didn't want to get cocky πŸ™‚


    On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" ... I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
    β€”Charles Babbage, Passages from the Life of a Philosopher

    How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537

  • The explanation is wrong, it's nothing to do with 'unassigned characters' (whatever they are).

    The variable is declared as VARCHAR, which defaults to varchar(1). The calculation results in -51, which is too long to fit into this variable, so it puts in a '*'.

  • Not sure about this, had to run the code, never encountered such case before, so it is interesting question, thanx.

    Thanks & Best Regards,
    Hany Helmy
    SQL Server Database Consultant

  • So Experts, which is the correct explanation. Either given by Eirikur Eiriksson or Toreador.

  • Try it out. You'll get the same result if you have

    DECLARE @ VARCHAR = 10

    or the following will return 45 (the ascii for '-')

    DECLARE @ VARCHAR(3) = 1952 + 03 + 11 - 2001 - 05 - 11;

    SELECT ASCII(@)

  • I'm no expert by any stretch of the imagination, but doing a bit of playing I have to agree with Toreador. If you change the code to this:

    DECLARE @ VARCHAR(3) = 1952 + 03 + 11 - 2001 - 05 - 11;

    SELECT ASCII(@) AS [the answer to life, the universe and prime numbers];

    you get an answer of 45 which is the ascii code for "-".

  • In the explanation I used the term unassigned for the lack of a better one as the value of the variable is neither truncated nor is it null.

    😎

  • hmmmm .... it can also be named as Theory of Everything πŸ˜›

    nice question and thanks for sharing Eirikur.

  • This was removed by the editor as SPAM

  • Toreador (2/26/2015)


    The explanation is wrong, it's nothing to do with 'unassigned characters' (whatever they are).

    The variable is declared as VARCHAR, which defaults to varchar(1). The calculation results in -51, which is too long to fit into this variable, so it puts in a '*'.

    Thanks, I had thought VARCHAR defaulted to 50 and could not figure why the answer was not 45.

  • djj (2/26/2015)


    Toreador (2/26/2015)


    The explanation is wrong, it's nothing to do with 'unassigned characters' (whatever they are).

    The variable is declared as VARCHAR, which defaults to varchar(1). The calculation results in -51, which is too long to fit into this variable, so it puts in a '*'.

    Thanks, I had thought VARCHAR defaulted to 50 and could not figure why the answer was not 45.

    When declared as a variable, I believe the default length is still 1. When used in a CONVERT function, it's 30.

  • This was removed by the editor as SPAM

  • Oh yeah...nice question, Erikur. I knew the answer without doing any math before even looking at the answers, but I still checked out the code to make sure. πŸ˜‰

  • This was removed by the editor as SPAM

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

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