Skip to content
Advertisement

Pivoting a table of survey data in SQL without PIVOT

I have a table called Responses which contains survey responses using the following structure.

This is data for two different survey responses. Each survey has 4 questions (QuestionIDs) but the last one (long text) is optional, so some responses only have 3 rows of data. The first question (QuestionID “1”) could also serve as a primary key for a survey response.

I’m trying to pivot the data so each QuestionID is it’s own column and so that each survey response is only one row. I’m using Zoho Analytics which I don’t believe supports PIVOT.

Thanks for any help!

Advertisement

Answer

You really don’t need PIVOT for this (you didn’t tag your database, likely MS SQL server):

PS: It has nothing to do with being web based.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement