title: Convert tabular data to XML using SQL Server
body: <p>I have a flattened table that contains columns that represent groups that need to be displayed in XML. Example data:</p>
  
  <pre><code>Market, Label, Style, Type
  XXX,    YYY,   JJJ,   111
  XXX,    YYY,   JJJ,   222
  XXX,    YYY,   JJJ,   333
  XXX,    YYY,   JJJ,   444    
  XXX,    YYY,   LLL,   111    
  XXX,    YYY,   LLL,   222    
  XXX,    YYY,   LLL,   333    
  XXX,    YYY,   LLL,   444
  </code></pre>
  
  <p>Using T-SQL what would be the best way to output the following:</p>
  
  <pre><code>&lt;Market value=XXX&gt;
      &lt;label value=YYY&gt;
         &lt;Style value=JJJ&gt;
            &lt;Type value=111&gt;
            &lt;/Type&gt;
            ...
         &lt;/Style&gt;
         &lt;Style value=LLL&gt;
            ...
         &lt;/Style&gt;
      &lt;/label&gt;
  &lt;/Market&gt;
  </code></pre>
  
  <p>Can I do this by using the XML Explicit clause in SQL Server?</p>