title: Extract data from XML string in SQL using XQuery
body: <p>I am trying to extract data from a XML string which is stored in my table in XMLString column as below..</p>
  
  <pre><code>VId   Uid   Name    TWd     XMLString 
  26    jti   jbreti  testell string in xml format
  26    Man   Lomond  Mcan    string in xml format
  26    mw    mlwTest tewWell string in xml format
  26    tot   teapot  te2Well string in xml format
  </code></pre>
  
  <p>XML string having below format. Its having multi level nodes also..</p>
  
  <pre><code>&lt;well uid="b4e952f9"&gt;
      &lt;name&gt;Demo&lt;/name&gt;
      &lt;field&gt;Fi Tk&lt;/field&gt;
      &lt;country&gt;India&lt;/country&gt;
      &lt;county&gt;South India&lt;/county&gt;
      &lt;region&gt;SiD&lt;/region&gt;
      &lt;block&gt;09-365&lt;/block&gt;
      &lt;timeZone&gt;+09:00&lt;/timeZone&gt;
      &lt;operator&gt;AACE Oil CO&lt;/operator&gt;
      &lt;operatorDiv&gt;AAACE South Australia&lt;/operatorDiv&gt;
      &lt;statusWell&gt;unknown&lt;/statusWell&gt;
      &lt;wellDatum defaultElevation="true" uid="SL"&gt;
          &lt;name&gt;Mean Sea Level&lt;/name&gt;
          &lt;code&gt;SL&lt;/code&gt;
      &lt;/wellDatum&gt;
      &lt;waterDepth uom="ft"&gt;269.0256&lt;/waterDepth&gt;
      &lt;wellLocation uid="loc-1"&gt;
          &lt;latitude uom="dega"&gt;-28.601403&lt;/latitude&gt;
          &lt;longitude uom="dega"&gt;137.444458&lt;/longitude&gt;
      &lt;/wellLocation&gt;
      &lt;commonData&gt;
          &lt;dTimCreation&gt;2012-04-10T13:17:45.959Z&lt;/dTimCreation&gt;
          &lt;dTimLastChange&gt;2013-11-08T14:42:56.340Z&lt;/dTimLastChange&gt;
      &lt;/commonData&gt;
  &lt;/well&gt;
  </code></pre>
  
  <p>I required few nodes from above XML &amp; this few nodes details is also in XML string as below..</p>
  
  <pre><code>&lt;well&gt;
      &lt;name&gt;&lt;/name&gt;       
      &lt;country&gt;&lt;/country&gt;
      &lt;block&gt;&lt;/block&gt;
      &lt;timeZone&gt;&lt;/timeZone&gt;
      &lt;wellDatum&gt;
          &lt;name&gt;&lt;/name&gt;
          &lt;code&gt;&lt;/code&gt;
      &lt;/wellDatum&gt;
      &lt;waterDepth&gt;&lt;/waterDepth&gt;
  &lt;/well&gt;
  </code></pre>
  
  <p>Now i need to extract nodes from 1st XML with node values string that are present in 2nd XML string.
  And out put should be also a XML string.
  Output string should be as below....</p>
  
  <pre><code>&lt;well uid="b4e952f9"&gt;
      &lt;name&gt;Demo&lt;/name&gt;
      &lt;country&gt;India&lt;/country&gt;
      &lt;block&gt;09-365&lt;/block&gt;
      &lt;timeZone&gt;+09:00&lt;/timeZone&gt;
      &lt;wellDatum defaultElevation="true" uid="SL"&gt;
          &lt;name&gt;Mean Sea Level&lt;/name&gt;
          &lt;code&gt;SL&lt;/code&gt;
      &lt;/wellDatum&gt;
      &lt;waterDepth uom="ft"&gt;269.0256&lt;/waterDepth&gt;
  &lt;/well&gt;
  </code></pre>
  
  <p>This all i want to be done in MSSQL only.
  Can anyone help me..</p>