foxtrot123
Registered User.
- Local time
- Today, 14:24
- Joined
- Feb 18, 2010
- Messages
- 57
I can use a simple query that shows survey responses like so:
Gender = What is you gender?
Color = What is favorite color(s)? (select all that apply)
Data on subjects is stored in tblSubjects.
Data on questions (QstnID, QstnBrief, etc.) is stored in tblQuestions. This table includes a variable to indicate of the question is a 'select all that apply' question.
Data on responses is stored in tblResponses.
I would like to convert these data to this structure:
In other words, the 'select all that apply questions" (like Color) need to return a separate variable for each response (using QstnBrief & "_" & Rspns).
If I didn't have 'select all that apply' questions, I could just use a simply crosstab to convert the data:
But this doesn't handle the select all that apply questions the way I need. Suggestions?
Code:
SubID QstnBrief Rspns
--------------------
1 Gender Male
1 Color Red
1 Color Blue
1 Color Orange
--------------------
2 Gender Female
2 Color Blue
--------------------
etc.
Color = What is favorite color(s)? (select all that apply)
Data on subjects is stored in tblSubjects.
Data on questions (QstnID, QstnBrief, etc.) is stored in tblQuestions. This table includes a variable to indicate of the question is a 'select all that apply' question.
Data on responses is stored in tblResponses.
I would like to convert these data to this structure:
Code:
SubID Gender Color_Red Color_Blue Color_Orange
1 Male Red Blue Orange
2 Female Blue
etc.
If I didn't have 'select all that apply' questions, I could just use a simply crosstab to convert the data:
Code:
TRANSFORM First(tblResponses.Rspns) AS FirstOfRspns
SELECT tblSubjects.SubID AS SubID
FROM tblSubjects INNER JOIN (tblQuestions INNER JOIN tblResponses ON tblQuestions.QstnID = tblResponses.QstnID) ON tblSubjects.SubID = tblResponses.RspnsID
GROUP BY tblSubjects.SubID
PIVOT tblQuestions.QstnBrief;