February 17, 2016 at 9:26 pm
Comments posted to this topic are about the item TRY_CONVERT smaller
February 17, 2016 at 10:22 pm
This was removed by the editor as SPAM
February 17, 2016 at 11:36 pm
Good question, thanks
...
February 18, 2016 at 1:09 am
To be pedantic, it depends on what edition you run the code. I know that the unwritten rule is assume the latest version but many people testing that, like I did, will get the wrong answer.
Still, I've got my point back by complaining about it
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
February 18, 2016 at 2:06 am
That's easy!
But, try to answer this:
"What's the resut?"
SELECT TRY_CONVERT(VARCHAR(1), {D'2011-MAY-01'})
:-D:-D:-D
February 18, 2016 at 2:19 am
Msg 195, Level 15, State 10, Line 1
'VARCHAR' is not a recognized built-in function name.
February 18, 2016 at 2:31 am
Msg 195, Level 15, State 10, Line 1
'VARCHAR' is not a recognized built-in function name.
for me here...and then I realised it was on a 2008 R2 instance...
Account Closed
February 18, 2016 at 2:52 am
I *almost* gave the answer that would have been correct for SELECT TRY_CONVERT(VARCHAR(1), 234523). Almost.
Also, I would like to know how many people would have selected NULL if that had been an option.
February 18, 2016 at 2:53 am
Carlo Romagnano (2/18/2016)
That's easy!But, try to answer this:
"What's the resut?"
SELECT TRY_CONVERT(VARCHAR(1), {D'2011-MAY-01'})
:-D:-D:-D
The correct answer to this question is "it depends".
Now my question to you is if you can figure out what it depends on.
(And no, I am not referring to the version of SQL Server)
February 18, 2016 at 3:06 am
Nice question. Thanks for sharing Steve.
February 18, 2016 at 3:27 am
Hugo Kornelis (2/18/2016)
Carlo Romagnano (2/18/2016)
That's easy!But, try to answer this:
"What's the resut?"
SELECT TRY_CONVERT(VARCHAR(1), {D'2011-MAY-01'})
:-D:-D:-D
The correct answer to this question is "it depends".
Now my question to you is if you can figure out what it depends on.
(And no, I am not referring to the version of SQL Server)
Only one answer:
Msg 241, Level 16, State 3, Line 1
Conversion failed when converting date and/or time from character string.
Because {D'2011-MAY-01'} is not a valid date! It doesn't dipend on language settings. The right format for ODBC datetime type is {D'2011-05-01'} (yyyy-mm-dd)
February 18, 2016 at 3:35 am
Ouch. Burned.
Thanks, Carlo! I really should have known that.
February 18, 2016 at 4:34 am
I got error message too so I failed the question.
Msg 195, Level 15, State 10, Line 3
'VARCHAR' is not a recognized built-in function name.
February 18, 2016 at 4:37 am
You should have included NULL. That way I could have gotten it wrong with NULL instead of error.
Shows you what reading the help for a function gives you. My gut said 2 but after reading the Microsoft information I thought it would be error.
Missed the part about truncation in TRY_CONVERT.
February 18, 2016 at 4:37 am
I was using SQL Server 2014 instance
Microsoft SQL Server Management Studio12.0.2000.8
Viewing 15 posts - 1 through 15 (of 34 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy