1

在此查询中:

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
  • 如何在 2 个旋转列中添加 b.idIndice 的值?

我有这个:

 id Documento  Index1 Index2

我需要

  id Documento 11 12

第二。我正进入(状态

Id Documento    Index1     Index2
13          11111111   11111111
14          11111111   11111111
16          11111      11111

它混合了这些值......值'11111111'应该在Index1列上,'11111'应该在Index2列上。

我能做些什么?

4

0 回答 0