March 17, 2016 at 9:39 pm
Comments posted to this topic are about the item Converting Questionable Dates
March 18, 2016 at 12:44 am
This was removed by the editor as SPAM
March 18, 2016 at 2:14 am
I may have misunderstood, but the Explanation states
If the input value cannot be converted to the resulting type, then an error is returned.
Looking at the MSDN article, it says
Returns a value cast to the specified data type if the cast succeeds; otherwise, returns null.
There is however one way in which an error can occur mentioned in the Remarks section of the MSDN article
However if you request a conversion that is explicitly not permitted, then TRY_CONVERT fails with an error.
Therefore, as far as I can tell, unless you were trying to convert an image, I don't think that the batch could return an error.
Philip
March 18, 2016 at 4:20 am
Returns a value cast to the specified data type, if the cast succeeds. Otherwise, NULL ist returned.
The Statement doesn't return Errors
🙂
March 18, 2016 at 4:25 am
I get an error:
Msg 195, Level 15, State 10, Line 1
'VARCHAR' is not a recognized built-in function name.
March 18, 2016 at 4:33 am
How do you use the statment? With a correct Syntax there is no error
March 18, 2016 at 4:58 am
Nice and simple, once you see the data type. That was probably the point. Thanks, Steve.
March 18, 2016 at 5:01 am
far (3/18/2016)
How do you use the statment? With a correct Syntax there is no error
I pasted the example into a query window and pressed F5
SELECT
TRY_CONVERT(VARCHAR(10), 'Mar 34, 2016 4:56 PM')
March 18, 2016 at 5:25 am
edwardwill (3/18/2016)
far (3/18/2016)
How do you use the statment? With a correct Syntax there is no errorI pasted the example into a query window and pressed F5
SELECT
TRY_CONVERT(VARCHAR(10), 'Mar 34, 2016 4:56 PM')
What version are you on? TRY_CONVERT was introduced in 2012. 2008 R2 (and presumably earlier) gives the error you state.
March 18, 2016 at 5:33 am
Andrew Watson-478275 (3/18/2016)
edwardwill (3/18/2016)
far (3/18/2016)
How do you use the statment? With a correct Syntax there is no errorI pasted the example into a query window and pressed F5
SELECT
TRY_CONVERT(VARCHAR(10), 'Mar 34, 2016 4:56 PM')
What version are you on? TRY_CONVERT was introduced in 2012. 2008 R2 (and presumably earlier) gives the error you state.
Good spot. Was "accidentally" connected to ancient box.
March 18, 2016 at 5:38 am
Except, when I cut-and-paste from the question:
SELECT
TRY_CONVERT(VARCHAR(10), 'Mar 34, 2016 4:56 PM')
I get an error:
Msg 195, Level 15, State 10, Line 3
'VARCHAR' is not a recognized built-in function name.
March 18, 2016 at 5:45 am
David Day (3/18/2016)
Except, when I cut-and-paste from the question:SELECT
TRY_CONVERT(VARCHAR(10), 'Mar 34, 2016 4:56 PM')
I get an error:
Msg 195, Level 15, State 10, Line 3
'VARCHAR' is not a recognized built-in function name.
I had the same issue, until I noticed I was connected to a pre-2012 server.
March 18, 2016 at 5:58 am
Then (with all due respect) the questions either need to indicate the version, or have version-specific options. Given the mess the latter would become, the former would be much more to the point (and much more in keeping with good test-writing practices... 😉 )
March 18, 2016 at 6:16 am
David Day (3/18/2016)
Then (with all due respect) the questions either need to indicate the version, or have version-specific options. Given the mess the latter would become, the former would be much more to the point (and much more in keeping with good test-writing practices... 😉 )
I wonder if you're relatively new round here? Lots of QotD are skunked - syntactically incorrect, semantically inexact or just plain wrong. I believe the setters think it's part of the test to work out what they meant, rather than what they wrote. Which, in my book (20 years a developer) would make them unemployable 😀
March 18, 2016 at 6:40 am
I also get error
Msg 195, Level 15, State 10, Line 2
'VARCHAR' is not a recognized built-in function name.
Viewing 15 posts - 1 through 15 (of 26 total)
You must be logged in to reply to this topic. Login to reply