I have 2 tables. TableA has a series of products with costs and TableB has a series of multipliers based on dates. For example:
TableA (Key: Product)
Product ID Cost Multiplier Code
ProductA 100 ABC
ProductB 200 DEF
ProductC 300 ABC
ProductD 400 JKL
TableB (Key: Date, Code)
Date Code Multiplier
01/01/12 ABC 100
01/01/12 DEF 200
01/01/12 GHI 300
01/01/12 JKL 400
16/03/12 ABC 300
20/06/12 ABC 900
15/05/12 DEF 700
Desired results:
TableA (Key: Product)
Product ID Cost Multiplier Code
ProductA 90000 ABC
ProductB 140000 DEF
ProductC 270000 ABC
ProductD 160000 JKL
What I would like to do is write a T-SQL script which loops through ALL of TableA and at the same time, multiply up the Cost column using TableB multipliers. So in the example of ProductA above, Cost should become 100 x 900 = 90,000.
It needs to use the latest modifier based on the date in TableB hence using 900 as the modifier.
Is this possible?