I want to combine two tables into one:
The first table: Payments
id | 2010_01 | 2010_02 | 2010_03 
1  | 3.000   | 500     | 0
2  | 1.000   | 800     | 0
3  | 200     | 2.000   | 300
4  | 700     | 1.000   | 100
The second table is ID and some date (different for every ID)
id | date         | 
1  | 2010-02-28   | 
2  | 2010-03-01   | 
3  | 2010-01-31   | 
4  | 2011-02-11   | 
What I'm trying to achieve is to create table which contains all payments before the date in ID table to create something like this:
id | date         | T_00  | T_01   | T_02
1  | 2010-02-28   | 500   | 3.000  | 
2  | 2010-03-01   | 0     | 800    | 1.000
3  | 2010-01-31   | 200   |        |
4  | 2010-02-11   | 1.000 | 700    |
Where T_00 means payment in the same month as 'date' value, T_01 payment in previous month and so on.
Is there a way to do this?
EDIT: I'm trying to achieve this in MS Access.
The problem is that I cannot connect name of the first table's column with the date in the second (the easiest way would be to treat it as variable)
I added T_00 to T_24 columns in the second (ID) table and was trying to UPDATE those fields
set T_00 =    
iif(year(date)&"_"&month(date)=2010_10,
but I realized that that would be to much code for access to handle if I wanted to do this for every payment period and every T_xx column.
Even if I would write the code for T_00 I would have to repeat it for next 23 periods.
 
     
    