I have a temporary table that is reloaded periodicaly. The data within this table must go to a target table (exactly the same structure), but, if I have duplicated values, it must check the last loaded data and update the target table.
Example:
TMP_DP_REGIAO
SG  NOME    LOADING_DATE
AM  RG_1102 19-FEB-14
RO  RG_1103 19-FEB-14
AP  RG_1104 19-FEB-14
TO  RG_1105 19-FEB-14
RO  RG_1106 19-FEB-14
After loaded, this data should go to TB_DP_REGIAO (that as I said, has the same structure).
The point is:
If SG in TMP already exists in TB, SQL must verify if this record in TMP has a greater LOADING_DATE than in TB. If so, update the TB. Otherwise, ignore it.
Can someone help on this issue?
Thanks in advance!
 
    