title: Pivot Table With Same Column Name in Sql Server
body: <p>I Have Table Called <code>TaxMaster</code>,I Need to convert Rows into columns so I am using pivot concept in sql server 2008. </p>
  
  <p>I Need sum of column percentage for Column Name <code>VAT</code> with <code>TaxId=1</code> and for Column Name <code>VAT</code> with <code>TaxId=3</code> distinctly but I am getting error as The column <code>VAT</code> was specified multiple times for <code>pvt</code></p>
  
  <pre><code>TaxId          Name          Code      Percentage
    1            VAT            VAT         10   
    2           Exempted        EXE         20
    3             VAT           VAT          5
  </code></pre>
  
  <p>My Query:</p>
  
  <pre><code>select  Name,VAT,Exempted,VAT 
  from 
  (
    select distinct Name, Percentage, TaxId, Code 
    from Masters.TaxMaster
  ) up 
  pivot 
  (
     sum(percentage) 
     for Code in(VAT,Exempted,Zero,NonVAT,VAT)
  ) as pvt 
  </code></pre>
  
  <p>Expected Output:</p>
  
  <pre><code>Name      Code      VAT      Exempted      VAT1
  VAT        VAT      10         0              0
  Exempted   EXE       0         20             0
  VAT        VAT       0          0             5
  </code></pre>