Converting XML

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715889

    Comments posted to this topic are about the item Converting XML

  • HappyGeek

    SSCoach

    Points: 18666

    Nice simple to end the week on thanks Steve.

    ...

  • Stewart "Arturius" Campbell

    SSC Guru

    Points: 71401

    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”

  • Eirikur Eiriksson

    SSC Guru

    Points: 182356

    Quick correction, 

    select TRY_CONVERT(XML, '')

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

  • Toreador

    SSChampion

    Points: 11231

    Thanks for reminding me why I never use this function!

  • Tom_Hogan

    Hall of Fame

    Points: 3462

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

  • bmg002

    SSC-Insane

    Points: 22392

    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?

  • trvudat

    Old Hand

    Points: 393

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

  • Toreador

    SSChampion

    Points: 11231

    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.

  • Ed Wagner

    SSC Guru

    Points: 286958

    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.

  • rhett.boyd

    SSC Veteran

    Points: 238

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

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

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