SELECT T1.EmployeeID, T1.PayoutYear,
(SELECT COUNT (*) FROM Table1 AS T2
WHERE (T1.PayoutYear >T2.PayoutYear OR T1.PayoutYear=T2.PayoutYear)
AND T1.EmployeeID=T2.EmployeeID) AS Iteration
FROM Table1 AS T1;
Results:
EmployeeID PayoutYear Iteration
100200 2008 3
100200 2009 6
100200 2010 12
This is my sample table:
EmployeeID PayoutYear
100 2008
100 2009
100 2010
200 2008
200 2009
and the results of my query:
EmployeeID PayoutYear Iteration
100 2008 1
100 2009 2
100 2010 3
200 2009 1
200 2010 2
Can you go into SQL view on the query and show me the Select statement you are using and maybe a few rows of your table?
Update: We were only missing a minor detail:
SELECT T1.EmployeeID, T1.PayoutYear,
(SELECT COUNT (*) FROM Table1 AS T2
WHERE (T1.PayoutYear >T2.PayoutYear OR T1.PayoutYear=T2.PayoutYear)
AND T1.EmployeeID=T2.EmployeeID
AND T1.PayoutID=T2.PayoutID) AS Iteration
FROM Table1 AS T1;
It works! Thanks.