Converting XML

  • Comments posted to this topic are about the item Converting XML

  • Nice simple to end the week on thanks Steve.

    ...

  • Nice one to end the week on, thanks Steve

    Interesting that TRY_CONVERT doesn't return a NULL in this instance, as it does for most other scenarios, e.g. select TRY_CONVERT(INT, 'Hello')

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • Quick correction, 

    select TRY_CONVERT(XML, '')

    returns an empty output, not NULL as stated in the question.
    😎

  • Thanks for reminding me why I never use this function!

  • Stewart "Arturius" Campbell - Thursday, July 27, 2017 11:40 PM

    Nice one to end the week on, thanks Steve

    Interesting that TRY_CONVERT doesn't return a NULL in this instance, as it does for most other scenarios, e.g. select TRY_CONVERT(INT, 'Hello')

    It returned a NULL for me when I ran it on my SQL 2012 machine (SP3 CU9).

  • Tom_Hogan - Friday, July 28, 2017 7:06 AM

    Stewart "Arturius" Campbell - Thursday, July 27, 2017 11:40 PM

    Nice one to end the week on, thanks Steve

    Interesting that TRY_CONVERT doesn't return a NULL in this instance, as it does for most other scenarios, e.g. select TRY_CONVERT(INT, 'Hello')

    It returned a NULL for me when I ran it on my SQL 2012 machine (SP3 CU9).

    I had the same result as Stewart when I ran it in SQL 2016 SP1.  Maybe they changed it in 2016?

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

  • I ran SELECT TRY_CONVERT(XML,'') on SSMS 2016, 2014, and 2012 and none of them return NULL.

  • trvudat - Friday, July 28, 2017 8:48 AM

    I ran SELECT TRY_CONVERT(XML,'') on SSMS 2016, 2014, and 2012 and none of them return NULL.

    That's because you can cast an empty string as XML.

  • bmg002 - Friday, July 28, 2017 8:27 AM

    Tom_Hogan - Friday, July 28, 2017 7:06 AM

    Stewart "Arturius" Campbell - Thursday, July 27, 2017 11:40 PM

    Nice one to end the week on, thanks Steve

    Interesting that TRY_CONVERT doesn't return a NULL in this instance, as it does for most other scenarios, e.g. select TRY_CONVERT(INT, 'Hello')

    It returned a NULL for me when I ran it on my SQL 2012 machine (SP3 CU9).

    I had the same result as Stewart when I ran it in SQL 2016 SP1.  Maybe they changed it in 2016?

    Nope.  I just ran it on SQL 2016 SP1 and it returned a NULL.

  • Ohh, thanks for information, bacause I did not understand(((((

Viewing 11 posts - 1 through 10 (of 10 total)

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