Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I'm Looking for some solution to my Problem

I have Crosstab Query

TRANSFORM Count(qrySickCount.TYPE) AS CountOfTYPE
SELECT qrySickCount.FullName, Count(qrySickCount.TYPE) AS TOTAL
FROM qrySickCount
WHERE (((qrySickCount.Exception)=False))
GROUP BY qrySickCount.FullName, qrySickCount.Exception
PIVOT Format([StartDate],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

Base on other Query

SELECT [FirstName] & " " & [LastName] AS FullName, tblLeave.StartDate, tblLeave.EndDate, DateDiff("d",[StartDate],[EndDate]) AS DaysOff, IIf([ReasonType]=4,"HOL",IIf([ReasonType]=5,"HOL",IIf([ReasonType]=1,"SICK",IIf([ReasonType]=2,"SICK",IIf([ReasonType]=3,"SICK"))))) AS TYPE, tblLeave.Exception
FROM tblEmployee INNER JOIN (tblReasonType INNER JOIN tblLeave ON tblReasonType.ID = tblLeave.ReasonType) ON tblEmployee.EmployeeNR = tblLeave.EmployeeNr
GROUP BY [FirstName] & " " & [LastName], tblLeave.StartDate, tblLeave.EndDate, DateDiff("d",[StartDate],[EndDate]), IIf([ReasonType]=4,"HOL",IIf([ReasonType]=5,"HOL",IIf([ReasonType]=1,"SICK",IIf([ReasonType]=2,"SICK",IIf([ReasonType]=3,"SICK"))))), tblLeave.Exception
HAVING (((IIf([ReasonType]=4,"HOL",IIf([ReasonType]=5,"HOL",IIf([ReasonType]=1,"SICK",IIf([ReasonType]=2,"SICK",IIf([ReasonType]=3,"SICK"))))))="SICK") AND ((tblLeave.Exception)=False));

And I'm Looking to see only people who have more then 3 SICK in Total only

When i place Criteria to my TOTAL column I reciving an error

"cannot have aggregate function in where clause"

its any way to pass that ??

or how to build a query what will show me peaple who have more then 3 SICK in a Year Base on my secund one ????

Thanks in Advance

1 solution

Try this:
SELECT qrySickCount.FullName, COUNT(qrySickCount.TYPE) AS TOTAL
FROM qrySickCount
WHERE (((qrySickCount.Exception)=False))
GROUP BY qrySickCount.FullName

For further information, please, see: HAVING Clause[^]
Share this answer
SebSCO 28-Jul-14 8:00am    
Thank you Very much Sir :)
Its working Perfect For me !
Maciej Los 28-Jul-14 8:49am    
You're welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900