title: Cannot use id on column title when pivoting and colum values are mixed
body: <p>In this query:</p>
  
  <pre><code>select *
  from
  (
    select distinct a.id as 'Id Documento', 
      b.valor, 'index'+cast(row_number() over(partition by a.id order by b.idIndice) as varchar(10)) rn
    from tgpwebged.dbo.sistema_Documentos as a
    join tgpwebged.dbo.sistema_Indexacao as b on a.id = b.idDocumento
    join tgpwebged.dbo.sistema_DocType as c on a.idDocType = c.id
    join tgpwebged.dbo.sistema_DocType_Index as d on c.id = d.docTypeId
    where d.docTypeId = 40 
    and  (b.idIndice = 11 AND b.valor = '11111111' OR b.idIndice = 12 AND b.valor = '11111')
  ) src
  pivot
  (
    max(valor)
    for rn in (Index1, Index2)
  ) piv
  </code></pre>
  
  <ul>
  <li>How to add the value of b.idIndice in the 2 pivoted columns?</li>
  </ul>
  
  <p>I have this:</p>
  
  <pre><code> id Documento  Index1 Index2
  </code></pre>
  
  <p>I need </p>
  
  <pre><code>  id Documento 11 12
  </code></pre>
  
  <p>Second. I am getting</p>
  
  <pre><code>Id Documento    Index1     Index2
  13          11111111   11111111
  14          11111111   11111111
  16          11111      11111
  </code></pre>
  
  <p>It is mixing the values... the value '11111111' should be on Index1 column and '11111' should be on Index2 columns.</p>
  
  <p>What can I do?</p>