March 21, 2015 at 6:31 pm
Comments posted to this topic are about the item The mysteries of life, the beginning of the 20th century
March 22, 2015 at 3:05 am
Very interesting question, thanx.
Thanks & Best Regards,
Hany Helmy
SQL Server Database Consultant
March 23, 2015 at 1:17 am
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:)
March 23, 2015 at 2:03 am
Simpaticissimo!
:-D:-D:-D:-D:-D
March 23, 2015 at 2:03 am
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...
March 23, 2015 at 2:23 am
Strange question...
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 23, 2015 at 3:38 am
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
March 23, 2015 at 3:47 am
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.
March 23, 2015 at 4:10 am
(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?
March 23, 2015 at 4:29 am
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.
March 23, 2015 at 5:18 am
An interesting one to be sure.
March 23, 2015 at 6:01 am
Nice to see that 4% of respondents chose the "Don't choose this" option. ๐
March 23, 2015 at 7:14 am
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.
March 23, 2015 at 8:53 am
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
March 23, 2015 at 10:25 am
andrew_dale (3/23/2015)
(2015+3+11)-(1900+1+1) gives 127as 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