Question

I am trying to calculate iterations of payouts. See below for sample data. This is what I have: This person has already been paid out each of their 3 installments (1 installment = 1 record).

+-----+----------+--------------+--------------+--------------+------------+--------+
|PytID|  PytGross| PayoutUnits  | SumOfPayouts  |   PaidOut   | PayoutYear | EmpID  |
+-----+----------+--------------+--------------+--------------+------------+--------+
|  1  |  $11,000 |     6.6667   |      3       |      3       |   2008     |  100   |
+-----+----------+--------------+--------------+--------------+------------+--------+
|  1  |  $11,000 |     6.6667   |      3       |      3       |   2009     |  100   |
+-----+----------+--------------+--------------+--------------+------------+--------+
|  1  |  $11,000 |     6.6666   |      3       |      3       |   2010     |  100   |
+-----+----------+--------------+--------------+--------------+------------+--------+

Using the SumOfPayouts (total number of times he/she should be paid out), I am trying to find the iteration of payouts. There is 1 payout per year. This is what I am trying to get (I didn't include EmpID b/c of spacing).

+-----+----------+--------------+--------------+--------------+------------+----------+
|PytID|  PytGross| PayoutUnits  | SumOfPayouts |   PaidOut    | PayoutYear |Iteration |
+-----+----------+--------------+--------------+--------------+------------+----------+
|  1  |  $11,000 |     6.6667   |      3       |      3       |   2008     |    1     |
+-----+----------+--------------+--------------+--------------+------------+----------+
|  1  |  $11,000 |     6.6667   |      3       |      3       |   2009     |    2     |
+-----+----------+--------------+--------------+--------------+------------+----------+
|  1  |  $11,000 |     6.6666   |      3       |      3       |   2010     |    3     |
+-----+----------+--------------+--------------+--------------+------------+----------+

Note: the ID field is specific to each payout as a whole. By that, I mean => A person has chosen to receive 3 payouts, so for this sample data, Employee 100 has elected to receive 20 units in 3 yearly installments. These 3 records have 2 things in common, an EmployeeID and a PytID.

It seems as though I need to use the PayoutYear to keep some kind of ROW_NUMBER() but since I am using Access it isn't an option. Does anyone have any idea on how to do this?

More information: I am pulling from a query (the SQL is very messy..). This is what the data looks like in the query I am pulling from.

AwardDate   PytGross    PytUnits    Remaining   PaidOut Sum EmployeeID  MCR_PytYear
12/26/2000  $11,500.06    6.67          0           3     3    100200       2008
12/26/2000  $11,500.06    6.67          0           3     3    100200       2009
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top