I am trying to return an Employee Name and Award Date if they have no prior award dates before dates the user specifies (these are fields on a form, StartDateTxt
and EndDateTxt
as seen below), aka their "first occurrence."
Example (AwardTbl only for simplicity):
AwardDate EmployeeID PlanID AwardedUnits
3/1/2005 100200 1 3
3/1/2008 100200 1 7
3/1/2005 100300 1 5
3/1/2013 100300 1 8
If I ran the query between the dates 1/1/2005 - 12/31/2005
, it would return 3/1/2005
and 100200
and 100300
. If I ran the query between 1/1/2008-12/31/2008
it would return nothing and likewise with 1/1/2013 - 12/31/2013
because those employees have already had an earlier award date.
I tried a couple different things, which gave me some weird results.
SELECT x.AstFirstName ,
x.AstLastName ,
y.AwardDate ,
y.AwardUnits ,
z.PlanDesc
FROM (AssociateTbl AS x
INNER JOIN AwardTbl AS y ON x.EmployeeID = y.EmployeeID)
INNER JOIN PlanTbl AS z ON y.PlanID = z.PlanID
WHERE y.AwardDate BETWEEN [Forms]![PlanFrm]![ReportSelectSbfrm].[Form]![StartDateTxt] And [Forms]![PlanFrm]![ReportSelectSbfrm].[Form]![EndDateTxt] ;
This query did NOT care if there was previous record or not, and I think that's where I am unsure of how to narrow down the query.
I also tried :
Min(AwardDate)
(didn't work)- A subquery in the
WHERE
clause that ordered byTOP 1 AwardDate ASC
, which only returned 1 record - A
DCount("*", "AwardTbl", "AwardDate < [Forms]![PlanFrm]![ReportSelectSbfrm].[Form]![StartDateTxt]") < 1
(This also did not differentiate whether or not it was the first occurrence of the AwardDate)
Please note: This is MS Access. There is no ROW_NUMBER()
or CTE
features.