Query to pull data from XML String stored in Nvarchar column

  • Hi, I have a column with datatype nvarchar where we are storing XML string, e.g below

    <?xml version='1.0' encoding='UTF-8'?><root available-locales="en_GB" default-locale="en_GB"><Title language-id="en_GB">Cookies</Title></root>

    now how can I pull "Cookies" from this string ?

  • pujain (3/20/2014)


    Hi, I have a column with datatype nvarchar where we are storing XML string, e.g below

    <?xml version='1.0' encoding='UTF-8'?><root available-locales="en_GB" default-locale="en_GB"><Title language-id="en_GB">Cookies</Title></root>

    now how can I pull "Cookies" from this string ?

    XQuery?

    Maybe this helps.

    DECLARE @String NVARCHAR(MAX) = '<?xml version=''1.0''?><root available-locales="en_GB" default-locale="en_GB"><Title language-id="en_GB">Cookies</Title></root>';

    SELECT (CAST(@string AS XML)).value('(/root/Title)[1]', 'NVARCHAR(MAX)') AS Title;

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

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