Hello,

I have a 2 tables

items codes: new item code, old item code
items quantities: item code, month, items quantity

There are several cases:

Case 1:
Z is the newer code, X is older code
X -> y -> Z

Case 2:
X -> Z
Y-> Z
Z is the newer code, X & Y are older code

I need to recalculate quantities table.

Case 1:

replace Z quantity by X quantity + Y quantity + Z quantity
replace Y quantity by X quantity + Y quantity

Before update:
x 10
Y 20
Z 30

After update:
x 10
Y 10+20=30
Z 10+20+30=60


Case 2:

replace Z quantity by X quantity + Y quantity + Z quantity

Before update:
x 10
Y 20
Z 30

After update:
x 10
Y 20
Z 10+20+30=60

How can I create a data structure to store 'items codes' with something like pointers (new code to old code)
so I will be able to find all the previous items codes of a selected item code ?

Thank you for your help