0

I'm trying to perform a pivot on the below dataset, In some cases there is only one unique ID, in others 2 and some cases more. I want to pivot the data in a way that shows for each unique ClaimID, the ResponseRejectCode Values are x,y,z ; having a column for each. Keeping in mind that the reject code will not always be an int and can be MR for example.

DataSet

I've reviewed the TechNet Example below; however, I cannot use the aggregate function for obvious reasons.

-- Pivot table with one row and five columns

SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days, 
0, 1, 2, 3, 4
FROM
(SELECT DaysToManufacture, StandardCost 
    FROM Production.Product) AS SourceTable
PIVOT
(
AVG(StandardCost)
FOR DaysToManufacture IN (0, 1, 2, 3, 4)
) AS PivotTable;

Any help or pointing me in the right direction would be greatly appreciated! Thank you

Taryn
  • 242,637
  • 56
  • 362
  • 405
  • You can use either MIN or MAX for your aggregate function, but I'm not clear on what your desired output is. You want a column for each reject code, but what would the values in those columns be? – Tab Alleman Jun 09 '16 at 14:14
  • Also see this duplicate: http://stackoverflow.com/questions/10404348/sql-server-dynamic-pivot-query – Tab Alleman Jun 09 '16 at 14:19

0 Answers0