aaearhart wrote:
>I'm getting an error: my DISTINCT query is called qry_WorkProjects
>
>qry_TimeReportProjects-------------------------------------------------------------------
>SELECT DISTINCT WorkProject, WorkHours, Employee, WorkMonth
> FROM tbl_TimeReport INNER JOIN tbl_TimeDetails ON
>tbl_TimeReport.TimeReportID = tbl_TimeDetails.TimeReportID
> WHERE (((tbl_TimeReport.TimeReportEmployee) Like [Enter employee's full
>name]) AND ((tbl_TimeReport.TimeReportMonth) Like [For what month?]))
>ORDER BY tbl_TimeDetails.WorkProject;
>
>produces (pretty much):
>**NOTE: results are not DISTINCT = problem #1 
>
>WorkProject WorkHours
>ProjectA 4
>ProjectA 5
>ProjectA 6
>ProjectA 10
>ProjectB 4
>ProjectB 8
>
>qry_WorkProjectHours---------------------------------------------------------------------
>SELECT T.WorkProject, Y.QRY_TimeReportProjects, Sum(T.WorkHours) AS
>SumOfWorkHours
>FROM tbl_TimeDetails As T INNER JOIN
> [SELECT X.WorkProject
> FROM QRY_TimeReportProjects As X
> GROUP BY X.WorkProject]. Y
> ON Y.WorkProject = T.WorkProject
>GROUP BY T.WorkProject, Y.QRY_TimeReportProjects
>
>-- so, as expected via qry_WorkProjects, I am asked to enter the employee's
>name and the month. however then I am asked to enter a value for
>Y.QRY_TimeReportProjects. I throw in "*" to return all and it works, but why
>am I getting this? Any ideas?
>
>
>> I think you do need two queries to do that.
>>
>> First create a query to get the distinct HH:
>> qryDistinctHH:
>> SELECT DISTINCT Reg, HH
>> FROM thetable
>>
>> Then this query will provide the desired results
>> SELECT T.Reg,
>> Y.DistinctHH,
>> Count(*) AS CountOfPol,
>> Sum(T.Amt) AS SumOfAmt
>> FROM thetable As T INNER JOIN
>> [SELECT X.Reg, Count(*) As DistinctPol
>> FROM qryDistinctHH As X
>> GROUP BY X.Reg]. Y
>> ON Y.Reg = T.Reg
>> GROUP BY T.Reg, Y.DistinctHH
>>
>> (Note the dot after the square bracket)
Something got mangled in the translation from your original
post to my reply and on into your last attempt ;-)
I think problem #1 is because you included WorkMonth in the
field list (with its Show box checked). I can't tell for
sure because you didn't paste all the results, but that's
what it looks like from here. It's unclear why you are
using the Like operator (instead of =) on the WorkMonth
criteria. Also note that an Order By clause not only won't
serve any useful purpose in theis query, but it will also
make the query run slower.
qry_TimeReportProjects-------------------------------------------------------------------
SELECT DISTINCT WorkProject, WorkHours
FROM tbl_TimeReport INNER JOIN tbl_TimeDetails
ON tbl_TimeReport.TimeReportID =
tbl_TimeDetails.TimeReportID
WHERE (tbl_TimeReport.TimeReportEmployee =
[Enter employee's full name])
AND (tbl_TimeReport.TimeReportMonth =
[For what month?])
qry_WorkProjectHours---------------------------------------------------------------------
SELECT T.WorkProject,
Y.DistinctPol,
Sum(T.WorkHours) AS SumOfWorkHours
FROM tbl_TimeDetails As T INNER JOIN
[SELECT X.WorkProject,
Count(*) As DistinctPol
FROM QRY_TimeReportProjects As X
GROUP BY X.WorkProject]. Y
ON Y.WorkProject = T.WorkProject
GROUP BY T.WorkProject, Y.DistinctPol
--
Marsh
MVP [MS Access]