title: Extract elements in xml to rows in select statement
body: <p>I have got xml column in my sql server 2008 database. XML sample in each row of my table</p>
  
  <pre><code>&lt;document&gt;
   &lt;part1&gt;
     &lt;listitem&gt;val1&lt;/listitem&gt;
     &lt;listitem&gt;val2&lt;/listitem&gt;
     &lt;listitem&gt;val3&lt;/listitem&gt;
   &lt;/part1&gt;
   &lt;part2&gt;
     &lt;listitem&gt;val4&lt;/listitem&gt;
   &lt;/part2&gt;
  &lt;/document&gt;
  </code></pre>
  
  <p>I would like to select all  elements from all rows. From sample above I should get four rows with listitem value.</p>
  
  <p><strong>The answer is</strong></p>
  
  <pre><code>select x.nd.value ('(.)[1]', 'varchar(250)') as ValuesFromXml
  from TableWithXmlColumn t cross apply t.XmlContent.nodes (
  '//listitem') x(nd);
  </code></pre>
  
  <p>Thanks for help</p>