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

  • JaimePC

    SSC Eights!

    Points: 864

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

  • Hany Helmy

    SSChampion

    Points: 13488

    Very interesting question, thanx.

  • palotaiarpad

    SSCarpal Tunnel

    Points: 4921

    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:)

  • Carlo Romagnano

    SSC-Insane

    Points: 21948

    Simpaticissimo!

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

  • Rune Bivrin

    SSCertifiable

    Points: 7794

    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.

  • Koen Verbeeck

    SSC Guru

    Points: 258965

    Strange question...

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

  • Sean of the Lynchmob

    Ten Centuries

    Points: 1038

    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

  • SQL Swerver

    Hall of Fame

    Points: 3074

    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.

  • andrew_dale

    Ten Centuries

    Points: 1215

    (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?

  • sipas

    Hall of Fame

    Points: 3236

    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.

  • Ed Wagner

    SSC Guru

    Points: 286980

  • dlaughlin 24148

    Old Hand

    Points: 355

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

  • sestell1

    SSChampion

    Points: 10230

    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.

  • webrunner

    SSC-Dedicated

    Points: 30227

    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

  • Revenant

    SSC-Forever

    Points: 42467

    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 23 total)

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