Search for a particular column name from with a XML column in SQL Server -


just wanted here. have situation need find data within <column name> tag shown in xml below.

i had issue badly formatted data exported in system, found piece there process import data out of system. have table contains xml stored.

i have iterate through whole table see if column name exists in particular id column , if return id. example table name sample , columns (id, importxml).

any on how can achieve ? new dealing xml within sql server.

<?xml version="1.0" encoding="utf-8"?>   <exportconfiguration id="sampleexport">        <definitions>             <clientname value="sample"/>             <filetype value="xml"/>             <filename>                  <value value="somevalue"/>               </filename>         <columns>              <column name="abc" datatype="string" value="test123"/>                  <column name="findthis" datatype="string" value="test456"/>                  </columns>      </definitions> </exportconfiguration>    

so above mentioned code want value within <columns>/<column name> = "findthis" findthis keyword , want id's of columns contain keyword findthis argument sake.

something this:

-- test table.  declare @xtable table (id int identity(1,1) primary key clustered, xmldata xml)  -- insert xml document. did one, same work multiple insert @xtable select '<?xml version="1.0" encoding="utf-8"?>               <exportconfiguration id="sampleexport">                    <definitions>                         <clientname value="sample"/>                         <filetype value="xml"/>                         <filename>                              <value value="somevalue"/>                           </filename>                     <columns>                          <column name="abc" datatype="string" value="test123"/>                              <column name="findthis" datatype="string" value="test456"/>                              </columns>                  </definitions>             </exportconfiguration>'  -- return table xml there attribute @ path "/exportconfiguration/definitions/columns/column" name "name" , value "findthis" select * @xtable xmldata.exist('/exportconfiguration/definitions/columns/column[@name eq "findthis"]') = 1 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -