Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

SQL to extract Data from XML string stored in nvarchar column Expand / Collapse
Posted Thursday, March 20, 2014 3:45 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, March 17, 2015 11:03 PM
Points: 301, Visits: 241
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 ?
Post #1552922
Posted Thursday, March 20, 2014 5:36 AM



Group: General Forum Members
Last Login: Today @ 12:54 PM
Points: 7,976, Visits: 19,104
declare @XML as xml

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

select @XML.value('(root/Title)[1]', 'varchar(50)')

Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

If your posting includes some T-SQL code, please surround the code with IFCode formatting tags. It helps readability a lot.
Post #1552955
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse