| Author |
Topic |
|
imranabdulaziz
Yak Posting Veteran
83 Posts |
Posted - 2009-09-02 : 00:19:20
|
| Dear All, I am using sql server 2005.I have three tables question , question_option , Exam_answer. Format of the table areQuestion TableQid Question Other detail1 What is your name Xyz2 Where do u reside abcQuestion_optionqid opno option Iscorrect1 1 Imran True1 2 khalid False1 3 raju False1 4 rahil False2 1 malad True2 2 bandra False2 3 Mahim falseExam_answer is where user response is saved during the exam. And is likepid Qid opno usrid corrct ISattempt1 1 2 User1 false True1 2 1 User1 true True1 1 1 User2 true True1 2 2 User2 false True1 1 User3 false False1 2 2 User3 false TrueNow I want to find wrong answer given by user for that paper.That is For paper 1 user1 has given wrong answer for qid 1. So I want to displayquestion Response given Isattempt Correct ans What is your name Khalid True imran Similarly paper 1 user2 has given wrong answer for qid 2 that should displayquestion Response given Isattempt Correct ans Where do u reside Bandra True malad Please suggest how to achieve |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-09-02 : 01:06:20
|
[code]declare @Question Table( Qid int, Question varchar(30), Other_detail varchar(30))insert into @Questionselect 1, 'What is your name', 'Xyz' union allselect 2, 'Where do u reside', 'abc'declare @Question_option table( Qid int, Optionno int, [Option] varchar(10), Iscorrect varchar(10))insert into @Question_optionselect 1, 1, 'Imran', 'True' union allselect 1, 2, 'khalid', 'False' union allselect 1, 3, 'raju', 'False' union allselect 1, 4, 'rahil', 'False' union allselect 2, 1, 'malad', 'True' union allselect 2, 2, 'bandra', 'False' union allselect 2, 3, 'Mahim', 'False'declare @Exam_answer table( Paperid int, Qid int, Optionno int, userid varchar(10), correct varchar(10), ISattempt varchar(10))insert into @Exam_answerselect 1, 1, 2, 'User1', 'False', 'True' union allselect 1, 2, 1, 'User1', 'True', 'True' union allselect 1, 1, 1, 'User2', 'True', 'True' union allselect 1, 2, 2, 'User2', 'False', 'True' union allselect 1, 1, 1, 'User3', 'False', 'False' union allselect 1, 2, 2, 'User3', 'False', 'True'select e.userid, q.Question, o.[Option], e.ISattempt, e.correct, a.[Option]from @Exam_answer e inner join @Question q on e.Qid = q.Qid inner join @Question_option o on e.Qid = o.Qid and e.Optionno = o.Optionno inner join @Question_option a on e.Qid = a.Qid and a.Iscorrect = 'True'-- unmask the below accordingly-- where e.correct = 'True'-- where e.correct = 'False'[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|