Hi @Michael Deaton
How can I have one occurrence of the ProductionEventId with the multiple values in their own columns?
Typically, you need a third column to distinguish each row of one ProductionEventId. As answered above, you could use Row_Number() function. And find the max number of rows for single ProductionEventId.If not familiar with pivot, you could also write query like this:
;WITH CTE AS
(
SELECT ProductionEventId,
value,
ROW_NUMBER()OVER(PARTITION BY ProductionEventId ORDER BY value) AS RNum
FROM YourTable
)
SELECT ProductionEventId
,MAX(CASE WHEN RNum = 1 THEN value ELSE NULL END) AS VALUE1
,MAX(CASE WHEN RNum = 2 THEN value ELSE NULL END) AS VALUE2
,MAX(CASE WHEN RNum = 3 THEN value ELSE NULL END) AS VALUE3
,MAX(CASE WHEN RNum = 4 THEN value ELSE NULL END) AS VALUE4
FROM CTE
GROUP BY ProductionEventId
Besides, if you're not attached to multiple columns, you can also consider comma-separated strings.
SELECT ProductionEventId
,STRING_AGG (value, ',') AS CommaSeparatedValues
FROM YourTable
GROUP BY ProductionEventId
Best regards,
Cosmog
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".