SQL Server XML parse issue -


i need parse xml sql server 2012 database. however, cannot find guide parse kind xml (here select top 2 table):

<ns2:software xmlns:ns2="http://www.example.com" xmlns:ns3="http://www.example2.com"><keyc>123-abc</keyc><statusc>y</statusc></ns2:software> <ns2:custom-data xmlns:ns2="http://www.example.com/2"><timec>2016.01.02</timec><customer>8r</customer><keyc>8r</keyc><statusc>n</statusc></ns2:custom-data> 

any help, how can parse "keyc" value xml?

so, can use select clause / or insert database.

you can use nodes , value entity:

declare @data table (xmltext xml) insert @data values     ('<ns2:software xmlns:ns2="http://www.example.com" xmlns:ns3="http://www.example2.com"><keyc>123-abc</keyc><statusc>y</statusc></ns2:software>'),     ('<ns2:custom-data xmlns:ns2="http://www.example.com/2"><timec>2016.01.02</timec><customer>8r</customer><keyc>8r</keyc><statusc>n</statusc></ns2:custom-data>')  select     nodes.keyc.value('.', 'varchar(50)') keyc @data d     cross apply xmltext.nodes('//keyc') nodes(keyc) 

this outputs following:

keyc ----------- 123-abc 8r 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -