I have a attempted pivot table that follows:
SELECT * FROM
(SELECT
[SurveyID]
,[SurveyQuestion]
,[SurveyQuestionID]
,[SequenceNumber]
FROM [Succession_Tool].[dbo].[SurveyQuestions]
) X
PIVOT
(
SUM([SurveyID]) FOR [SurveyQuestion] IN (A,B,C)
) Z
I get the following error:
Msg 325, Level 15, State 1, Line 9
Incorrect syntax near 'PIVOT'. You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the SET COMPATIBILITY_LEVEL option of ALTER DATABASE.
I tried to rewrite it based on some other articles on stackoverflow and other places such as this or this but they both lead back to the same error above. Is there something simple I'm missing? For what its worth, my compatibility_level is 100, this is SQL Serer 2008, I don't need the aggregation because just want the formatting to spit out to a CSV file
UPDATE: I rewrote the query again below following these directions
WITH MYSurveyQuestions AS
(SELECT
[SurveyID]
,[SurveyQuestion]
,[SurveyQuestionID]
,[SequenceNumber]
FROM [Succession_Tool].[dbo].[SurveyQuestions]
)
SELECT * FROM MYSurveyQuestions
PIVOT
(SUM(SURVEYID) FOR SurveyQuestion
IN (A,B,C,D,E,F)) AS PVT
Now I get the following error:
Msg 102, Level 15, State 1, Line 11 Incorrect syntax near ')'.
Unfortunately, that has the same meaning as the first error to me because I still can't find the error(shrug)...I feel like I'm closer though. Double clicking the error highlights
(SUM(SURVEYID) FOR SurveyQuestion