You can use the PIVOT function to get the result but since you need to return multiple rows for each Capacity
, you will want to use a windowing function like row_number()
that will generate a unique sequence for each Capacity
and CDate
combination:
SELECT Capacity, [2014-04-14], [2014-04-15]
FROM
(
SELECT Capacity,
CDate,
Name,
row_number() over(partition by capacity, cdate
order by capacity) seq
FROM @Temp
) d
PIVOT
(
MAX(name)
FOR CDate IN ([2014-04-14], [2014-04-15])
) piv
ORDER BY Capacity;