I have two tables which looks as below
First table :
DealNum CurrencyValue CurrencyCode Date
110 100 AA 01/12/2011
111 200 AB 01/11/2011
112 120 AC 01/10/2011
113 20 AA 01/11/2011
110 103 AD 01/12/2011
115 200 AD 01/11/2011
119 120 AG 01/10/2011
130 20 AK 01/11/2011
Second Table
CurrencyCode OCT NOV DEC JAN ..
AA 0.91 0.88 0.9 0.94
AB 0.9 0.8 0.96 0.89
AC 0.81 0.79 0.82 0.84
AD 0.4 0.41 0.42 0.39
AE 0.9 0.92 0.91 0.94
AF 0.8 0.82 0.83 0.81
now I want to add the data from the second table to first table in a new column with the following conditions
1.It has to do based on the CurrencyCode and month
2.If the deal is from DEC and currencyCode is AA , then it has to take the value 0.9,
if the deal is from NOV and currencyCode is AA , then it has to take the value 0.88..
So, The result should look like this
DealNum CurrencyValue CurrencyCode Date NewColumn
110 100 AA 01/12/2011 0.9
111 200 AB 01/11/2011 0.8
112 120 AC 01/10/2011 0.81
113 20 AA 01/11/2011 0.88
110 103 AD 01/12/2011 0.42
115 200 AD 01/11/2011 0.41
119 120 AG 01/10/2011 --
130 20 AK 01/11/2011 --
I have no clue on how to do this with comparing row value of month from first table to column value of month in second table. Please help me with this..
Thanks in advance.
Cheers,
Harish.
This should work, although you second table is not designed well.