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.

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

  • 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. πŸ˜‰

  • My takeaway is that the Ultimate Answer to Life, the Universe, and Everything is not, in fact, 42 but is instead '-'. Meaningful when one considers the answer is really the '-' between the dates (birth - death). πŸ˜›

    I think Mr. Adams is rolling over with laughter in his grave... Thanks for sharing.

  • There was no alternative other than 42 given the context of the question. I didn't even read the question before answering. Of course my soccer jersey has that number and "Dent" for the name. It is fun to see who on other teams gets it. πŸ˜›

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (2/26/2015)


    There was no alternative other than 42 given the context of the question. I didn't even read the question before answering. Of course my soccer jersey has that number and "Dent" for the name. It is fun to see who on other teams gets it. πŸ˜›

    I only read the question because I was puzzled by the prime part. I am ashamed to say I've never read the book :blush:


    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

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

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