I have query as mentioned below
x
SELECT Project
,STATUS
,count(*) AS [count]
FROM Defect
GROUP BY Project
,STATUS
ORDER BY Project
which will return a table like
I’m trying to PIVOT this result as below
Advertisement
Answer
You can try the below way –
SELECT * FROM
(
SELECT Project,STATUS,count(*) AS cnt FROM Defect GROUP BY Project,STATUS
) t
PIVOT(
sum(cnt)
FOR STATUS IN (
[Build Assigned],
[Build Delivered],
[Closed],
[Eng. Build Delivered],
[New],
[Non-Issue],
[Open],[Pending])
) AS pivot_table