nvwildfire
Technical User
Hi List!
I am having a problem with using the DISTINCT operator in and aggregate function like COUNT in Access 2002. I found some information on the Microsoft knowledge base acknowledging that there is a know problem with some of the ANSI-92 SQL standards in Access 2002 specifically using DISTINCT in aggregate functions (Microsoft Knowledge Base Article - 306250). They give a work around but I am not sure how to implement it under a complex SQL statement.
So if you have a query like this:
SELECT SUM (DISTINCT field1) from Table1
MS says to work around the error in Access 2002 to write the statement like this:
SELECT Sum(Field1) FROM (SELECT DISTINCT Field1 from table1)
My problem is that I have many joins and don't know how to through a sub select in. So here is what I have right now for a sql statement:
SELECT Count(tblstudent!studentID) AS NStudents, tblAssistantship.Assistantship, tblDegree.Degree, tblFiscalPay.FiscalYear, Round((Sum(tblsalary!salary*tblfiscalpay!duration))/((Sum(tblfiscalpay!duration))/30.416),0) AS MonthlySalary, Round(Max(tblsalary.salary*30.416),0) AS SMaxSalary, Round(Min(tblsalary.salary*30.416),0) AS SMinSalary, tbladvisor!lastname & ", " & tbladvisor!firstname AS AdvisorName
FROM tblStudent INNER JOIN ((tblDegree INNER JOIN (tblAdvisor INNER JOIN tblStudentAttributes ON tblAdvisor.FacultyID=tblStudentAttributes.FacultyID) ON tblDegree.DegreeID=tblStudentAttributes.DegreeID) INNER JOIN ((tblAssistantship INNER JOIN tblSalary ON tblAssistantship.AssistantshipID=tblSalary.AssistantshipID) INNER JOIN tblFiscalPay ON tblSalary.JobID=tblFiscalPay.JobID) ON tblStudentAttributes.StudentAttributesID=tblSalary.StudentAttributeID) ON tblStudent.StudentID=tblStudentAttributes.StudentID
GROUP BY tblAssistantship.Assistantship, tblDegree.Degree, tblFiscalPay.FiscalYear, tbladvisor!lastname & ", " & tbladvisor!firstname;
What I would like to add is another column called NStudents by adding this:
COUNT(DISTINCT tblStudent.StudentID) AS NStudents
But I cannot figure out how to do it with the MS workaround.
Any help would be greatly appreciated.
Karl Krauter
krauter@unr.edu
I am having a problem with using the DISTINCT operator in and aggregate function like COUNT in Access 2002. I found some information on the Microsoft knowledge base acknowledging that there is a know problem with some of the ANSI-92 SQL standards in Access 2002 specifically using DISTINCT in aggregate functions (Microsoft Knowledge Base Article - 306250). They give a work around but I am not sure how to implement it under a complex SQL statement.
So if you have a query like this:
SELECT SUM (DISTINCT field1) from Table1
MS says to work around the error in Access 2002 to write the statement like this:
SELECT Sum(Field1) FROM (SELECT DISTINCT Field1 from table1)
My problem is that I have many joins and don't know how to through a sub select in. So here is what I have right now for a sql statement:
SELECT Count(tblstudent!studentID) AS NStudents, tblAssistantship.Assistantship, tblDegree.Degree, tblFiscalPay.FiscalYear, Round((Sum(tblsalary!salary*tblfiscalpay!duration))/((Sum(tblfiscalpay!duration))/30.416),0) AS MonthlySalary, Round(Max(tblsalary.salary*30.416),0) AS SMaxSalary, Round(Min(tblsalary.salary*30.416),0) AS SMinSalary, tbladvisor!lastname & ", " & tbladvisor!firstname AS AdvisorName
FROM tblStudent INNER JOIN ((tblDegree INNER JOIN (tblAdvisor INNER JOIN tblStudentAttributes ON tblAdvisor.FacultyID=tblStudentAttributes.FacultyID) ON tblDegree.DegreeID=tblStudentAttributes.DegreeID) INNER JOIN ((tblAssistantship INNER JOIN tblSalary ON tblAssistantship.AssistantshipID=tblSalary.AssistantshipID) INNER JOIN tblFiscalPay ON tblSalary.JobID=tblFiscalPay.JobID) ON tblStudentAttributes.StudentAttributesID=tblSalary.StudentAttributeID) ON tblStudent.StudentID=tblStudentAttributes.StudentID
GROUP BY tblAssistantship.Assistantship, tblDegree.Degree, tblFiscalPay.FiscalYear, tbladvisor!lastname & ", " & tbladvisor!firstname;
What I would like to add is another column called NStudents by adding this:
COUNT(DISTINCT tblStudent.StudentID) AS NStudents
But I cannot figure out how to do it with the MS workaround.
Any help would be greatly appreciated.
Karl Krauter
krauter@unr.edu