Ho un problema Ho visto altri con problemi simili, ma le risposte per quelle non sembrano applicabili alla mia situazione. Questa è la mia prima domanda, quindi perdonami in anticipo per eventuali problemi di formattazione e grazie per qualsiasi suggerimento che puoi fornire.Il mio PIVOT restituisce le righe duplicate con valori di colonna pivot in ogni riga
mio #TempTBData
assomiglia a questo:
InvoiceProductID ContactID ContactName ChargeDescription Amount
191 1832 Gloria Cheung Cruise Fare 500.00
191 1886 John Novosad Cruise Fare 500.00
191 2011 Christopher Yong Cruise Fare 100.00
Il mio codice perno è simile al seguente:
SELECT DISTINCT<br>
[InvoiceProductID]<br>
,[ChargeDescription]<br>
,[Christopher Yong],[Gloria Cheung],[John Novosad]<br>
FROM #TempTBData<br>
PIVOT(MAX([Amount])<br>
FOR [ContactName] IN ([Christopher Yong],[Gloria Cheung],[John Novosad])) AS PVTTable
..E mio risultato PIVOT assomiglia a questo:
InvoiceProductID ChargeDescription Christopher Yong Gloria Cheung John Novosad
191 Cruise Fare NULL NULL 500.00
191 Cruise Fare NULL 500.00 NULL
191 Cruise Fare 100.00 NULL NULL
.. E vorrei che il risultato fosse:
InvoiceProductID ChargeDescription Christopher Yong Gloria Cheung John Novosad
191 Cruise Fare 100.00 500.00 500.00
Per favore fatemi sapere cosa sto facendo male.
Grazie @Ajmot per l'aiuto formattazione! Non riuscivo a vedere come formattare le cose in questo modo all'interno dell'editor wysiwyg limitato. – Scott