I have Data in a table that i'm attempting to pivot from rows to columns, and the script im using is working, but the pivot is coming up with NULL for everything.
Here's the source data:
Catalog Class Nbr ID Status Grade
281 82142 5000293644 Enrolled 1
295 12128 1012642448 Enrolled 1
296 12124 1012642448 Enrolled 4
280 82141 5000289133 Enrolled 4
295 10528 1012923963 Enrolled 1
And the Pivot Query:
SELECT *
FROM (
SELECT [ID], [Catalog], [Grade]
From CSNCombined.dbo.csnName
) as c
PIVOT
(
SUM([Grade])
FOR [Catalog] IN ([198], [281], [280], [295], [296], [297])
)
AS PVT
The query executes fine, but all values are NULL.
Catalog
the same values being used as the new column names here --FOR [Catalog] IN ([198], [281], [280], [295], [296], [297])
?Grade
nullable? If so, does this return any rows:SELECT * FROM csnName WHERE Grade IS NULL AND Catalog IN (198,281,...);
? Also, please clarify what "all values" means - every single column, or just those coming from the pivot?