Converting Questionable Dates

  • Comments posted to this topic are about the item Converting Questionable Dates

  • This was removed by the editor as SPAM

  • 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

  • Returns a value cast to the specified data type, if the cast succeeds. Otherwise, NULL ist returned.

    The Statement doesn't return Errors

    🙂

  • I get an error:

    Msg 195, Level 15, State 10, Line 1

    'VARCHAR' is not a recognized built-in function name.

  • How do you use the statment? With a correct Syntax there is no error

  • Nice and simple, once you see the data type. That was probably the point. Thanks, Steve.

  • 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')

  • edwardwill (3/18/2016)


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

    What version are you on? TRY_CONVERT was introduced in 2012. 2008 R2 (and presumably earlier) gives the error you state.

  • 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 error

    I 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.

  • 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.

  • 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.

  • 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... 😉 )

  • 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 😀

  • 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