Question

I am trying to create query which returns the list of students who passed an exam after, At least X number of failures.To achieve this i wrote the following query but i am getting the following error as well:

Error in list of values in IN clause. Unable to parse query text.

I am sure the list of values in IN clause are fine though what i don't understand is why it is complaining?! Here is the query in question :

SELECT  StudentID
    FROM    tblStudents
    WHERE   (Sex = @Sex) AND (StudentID IN
                                        (SELECT StudentID
                                        FROM    tblTest
                                        WHERE   (TestID = @TestID) AND (@APass = 'true') AND (Score IN (27, 28, 29, 30)))
                                        GROUP BY StudentID, TestID
                                        HAVING   (COUNT(*) = 1))/*By this i meant find the the user who has passed the exam (finally)*/
                        AND (StudentID IN
                                        (SELECT  StudentID
                                        FROM     tblTest
                                        WHERE   (TestID = @TestID) AND (Score NOT IN (27, 28, 29, 30)))
                                        GROUP BY StudentID, TestID
                                        HAVING        (COUNT(*) >= @Times))/*And By this i meant only return students which passed the exam after x times of failing it*/
Was it helpful?

Solution

Your sub-queries seem to have one too many ) just after the IN clauses - these should be moved to the HAVING lines.

SELECT  StudentID
FROM    tblStudents
WHERE   (Sex = @Sex) AND (StudentID IN
                (SELECT StudentID
                FROM    tblTest
                WHERE   (TestID = @TestID) AND (@APass = 'true') AND (Score IN (27, 28, 29, 30))
                GROUP BY StudentID, TestID
                HAVING   (COUNT(*) = 1)))/*By this i meant find the the user who has passed the exam (finally)*/
AND (StudentID IN
                (SELECT  StudentID
                FROM     tblTest
                WHERE   (TestID = @TestID) AND (Score NOT IN (27, 28, 29, 30))
                GROUP BY StudentID, TestID
                HAVING        (COUNT(*) >= @Times)))/*And By this i meant only return students which passed the exam after x times of failing it*/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top