The mysteries of life, the beginning of the 20th century

  • Comments posted to this topic are about the item The mysteries of life, the beginning of the 20th century

  • Very interesting question, thanx.

    Thanks & Best Regards,
    Hany Helmy
    SQL Server Database Consultant

  • Without running the code i thought, the variable declaration will throw an error.:-D

    (Just to be sure: aren't we in the 21st century? :cool:)

  • Simpaticissimo!

    :-D:-D:-D:-D:-D

  • Can't really say anything positive about a question which relies on regional settings for correct answer, and which doesn't really promulgate any useful knowledge. Why would I want to do anything like that? Or even encounter it in any existing code? It's just too arcane...


    Just because you're right doesn't mean everybody else is wrong.

  • Strange question...

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

  • palotaiarpad (3/23/2015)


    Without running the code i thought, the variable declaration will throw an error.:-D

    I thought the same. So, having been told I had got it wrong, I ran the code and got the following:

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near '('.

    Msg 137, Level 15, State 2, Line 2

    Must declare the scalar variable "@".

    I am stuck as to where the 'correct' answer of '77' is displayed - ???????

    Sean

  • I personally thought this code would error due to variable-declaration handling so I did learn a little ๐Ÿ™‚

    But I don't see the connection between the title and the question raised.

  • (2015+3+11)-(1900+1+1) gives 127

    as that field is declared as a smalldatetime, it becomes the 126th day of the year 1900 (0th day is 1900-01-01)

    this is confirmed by running select @ which returns 1900-05-08 00:00:00

    the ASCII function takes a varchar so the smalldatetime is implicitly converted to varchar first

    if we explicitly convert it using select cast(@ as varchar (20) ) I get May 8 1900 12:00AM

    the ASCII function takes the first character from the varchar, which is the letter M so returns 77 which is its ASCII code

    so I agree with Rune Bivrin, in that it is a stupid question as it relies on regional settings, and why would you ever what the ASCII value of the first character from the date?

  • Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near '('.

    Msg 137, Level 15, State 2, Line 2

    Must declare the scalar variable "@".

    I am stuck as to where the 'correct' answer of '77' is displayed - ???????

    Sean

    Depends on your version of SQL Server. E.g. in 2005 run:

    declare @ smalldatetime

    set @ = (2015+3+11)-(1900+1+1)

    select ascii(@)

    and you may get 77 depending on your regional settings.

    Odd one but I'm sure someone learns something even from the 'why would you ever want to do this?' type questions.

  • Nice to see that 4% of respondents chose the "Don't choose this" option. ๐Ÿ™‚

  • Rune Bivrin (3/23/2015)


    Can't really say anything positive about a question which relies on regional settings for correct answer, and which doesn't really promulgate any useful knowledge. Why would I want to do anything like that? Or even encounter it in any existing code? It's just too arcane...

    I found it very interesting that you could declare '@' as a variable. I did not know that. I could see this happening accidentally at some point, so it's good to know that won't actually throw an error.

  • Thanks for the question. But shouldn't the SSC assistant's name be Little Stevie? ๐Ÿ˜‰

    - webrunner

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

  • andrew_dale (3/23/2015)


    (2015+3+11)-(1900+1+1) gives 127

    as that field is declared as a smalldatetime, it becomes the 126th day of the year 1900 (0th day is 1900-01-01)

    this is confirmed by running select @ which returns 1900-05-08 00:00:00

    the ASCII function takes a varchar so the smalldatetime is implicitly converted to varchar first

    if we explicitly convert it using select cast(@ as varchar (20) ) I get May 8 1900 12:00AM

    the ASCII function takes the first character from the varchar, which is the letter M so returns 77 which is its ASCII code

    so I agree with Rune Bivrin, in that it is a stupid question as it relies on regional settings, and why would you ever what the ASCII value of the first character from the date?

    Well, the category is 'Humor'...

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

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