November 14, 2005 at 2:44 am
I want to create a report for a survey. The survey consists of 5 Questions and each questions has 6 options like (Strongly Disagree, I Disagree, Fairly, Agree, Strongly Agree, Dont Know). I created a radio button set which will put values like (1,2,3,4,5,6) depend on the option.
| Question | I Strongly Agree | I Agree | Fairly Agree | I Disagree | I Strongly Disagree | Don't Know | |
| 1. | wr747 | ||||||
| 2. | wret12 | ||||||
| 3. | wert6456 | ||||||
| 4. | wret356 | ||||||
| 5.
| wert457 | ||||||
| | ||||||
I want a final report like this
| Q. No | I Strongly Agree | I Agree | Fairly Agree | I Disagree | I Strongly Disagree | Don't Know | Total |
| 1. | |||||||
| 2. | |||||||
| 3. | |||||||
| 4. | |||||||
| 5. |
Database is
name:msurvey
id int
date smalldatetime
q1 int
q2 int
q3 int
q4 int
q5 int
Please help me solve this issue
Regards
Saiju Thomas
November 14, 2005 at 3:21 am
for a better design you might want to put the question in the row rather than on the column
table msurvey
- id int
- date small datetime
- q_no integer
- q_val integer
based on above structure the query you want is
select id, date, q_no,
case when q_val = 1 then
1
else
0
end as "Strongly Agree",
case when q_val = 2 then
1
else
0
end as "Agree",
case when q_val = 3 then
1
else
0
end as "Fairly Agree",
case when q_val = 4 then
1
else
0
end as "Disagree",
case when q_val = 5 then
1
else
0
end as "Strongly Disagree",
case when q_val = 6 then
1
else
0
end as "Don't Know"
from msurvey
where id = @yourid -- your where condition for id
and date = @yourdate -- your where condition for date
order by q_no
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply