Converting Questionable Dates

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 714389

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

  • This was removed by the editor as SPAM

  • philip.cullingworth

    SSCrazy

    Points: 2150

    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

  • far

    SSCertifiable

    Points: 5533

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

    The Statement doesn't return Errors

    🙂

  • edwardwill

    SSCarpal Tunnel

    Points: 4744

    I get an error:

    Msg 195, Level 15, State 10, Line 1

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

  • far

    SSCertifiable

    Points: 5533

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

  • Ed Wagner

    SSC Guru

    Points: 286951

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

  • edwardwill

    SSCarpal Tunnel

    Points: 4744

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

  • Andrew Watson-478275

    SSCarpal Tunnel

    Points: 4422

    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.

  • edwardwill

    SSCarpal Tunnel

    Points: 4744

    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.

  • David Day

    SSC Enthusiast

    Points: 128

    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.

  • edwardwill

    SSCarpal Tunnel

    Points: 4744

    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.

  • David Day

    SSC Enthusiast

    Points: 128

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

  • edwardwill

    SSCarpal Tunnel

    Points: 4744

    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 😀

  • g.maxfield

    Default port

    Points: 1414

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

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