Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Select XML data

$
0
0

Okay, this should be simple, but I can't get it to work. I have XML data in an ntext field (developers, what can you do), that I need to parse out a value from. The data looks like this:

<UDFValidatedValue xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/stuff.UDF">
  <Description>North America</Description>
  <Value>North America</Value>
  <ValueType>String</ValueType>
</UDFValidatedValue>

Now, I wrote my query like this:

 SELECT cast(GeographicRegion as xml).query('/UDFValidatedValue/Description')  as Region
FROM   CompanyUdf

But I get a blank for the column instead if the data for Description.

I tried this:

SELECT cast(GeographicRegion as xml).value('(/UDFValidatedValue/Description)[1]', 'nvarchar(max)')  as Region
FROM   CompanyUdf

and I get a "NULL" value.

What am I doing wrong?

Thanks in advance!

mpleaf


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>