title: Dynamic creation of fields from varying xml structure in sql server 2012
body: <p>One of the columns in my  log table is of type xml, the xml field stores parameters passed to different stored procedures executed in database. So each xml has got a different format and only the root node stays the same. I want to create a table to copy the data values in xml along with other fields in log table(basically expand each row). Any ideas on how to implement this in sql server 2012?</p>
  
  <p>Sample XML</p>
  
  <pre><code>&lt;Notes&gt;
    &lt;Parameters&gt;
      &lt;DimCalendarId&gt;20150505&lt;/DimCalendarId&gt;
      &lt;RangeCheckStartDate&gt;2015-04-01 00:00:00.000&lt;/RangeCheckStartDate&gt;
      &lt;RangeCheckEndDate&gt;2015-06-30 23:59:59.000&lt;/RangeCheckEndDate&gt;
      &lt;StartPeriodDate&gt;2015-05-05 00:00:00.000&lt;/StartPeriodDate&gt;
      &lt;EndPeriodDate&gt;2015-05-05 23:59:59.000&lt;/EndPeriodDate&gt;
      &lt;ActiveRecordDate&gt;2015-05-05 18:00:00.983&lt;/ActiveRecordDate&gt; 
      &lt;PeriodTypeId&gt;4&lt;/PeriodTypeId&gt;
      &lt;ProcessingSourceId&gt;2&lt;/ProcessingSourceId
    &lt;/Parameters&gt;
  &lt;/Notes&gt; 
  </code></pre>