A family of Microsoft relational database management systems designed for ease of use.
Hi Ken
Thanks for your quick reply.
If you look at this snapshot of my Responses table, you'll see that QuestionID 34 had 2 answers and 35 had 4. Your query counts these and therefore not aligning with the count of total questions.
| QuestionnaireID | ResponseSessionID | Answer | QuestionID |
|---|---|---|---|
| 7 | 14 | Yes | 31 |
| 7 | 14 | Yes | 32 |
| 7 | 14 | Annex 11 Applicable | 34 |
| 7 | 14 | 21 CFR Part 11 Applicable | 34 |
| 7 | 14 | 21 CFR Part 11 Applicable | 35 |
| 7 | 14 | Annex 11 Applicable | 35 |
| 7 | 14 | GAMP Category 1 | 35 |
| 7 | 14 | GxP Applicable | 35 |
As I stated before, I don't want to count the QuestionID per Questionnaire, per Response Session more than once. All I need to know is if the question was answered or not. In the table above, the desired total count of Questions answered should be 4.
I'm close...I slightly modified your sql as follows:
SELECT DISTINCT Questionnaires.QuestionnaireID, QuestionnaireName,
(SELECT COUNT(*)
FROM QuestionnaireQuestions
WHERE QuestionnaireQuestions.QuestionnaireID = Questionnaires.QuestionnaireID)
AS CountOfQuestions,
COUNT(*) AS CountOfResponses,
CountOfResponses/CountOfQuestions*100 AS PercentageCompleted
FROM Questionnaires INNER JOIN
(SELECT DISTINCT QuestionnaireID, QuestionID, ResponseSessionID
FROM RESPONSES) AS DistinctResponses
ON Questionnaires.QuestionnaireID = DistinctResponses.QuestionnaireID
GROUP BY Questionnaires.QuestionnaireID, QuestionnaireName;
I removed the portion that would calculate the total number of questions asked over one or more sessions per questionnaire (this is the number of questions per questionnaire multiplied by the number of sessions per questionnaire).
The only thing left is to have the query only count the QuestionID once per Response Session.
Charlie