I have a SQL statement for merging edits from one table to another. I.e.
UPDATE f
SET f.AUDAPLCDE = m.AUDAPLCDE, f.AUDSTF_NO = m.AUDSTF_NO,
f.AUDUPD_ID = m.AUDUPD_ID, f.AUDUPDDTE = m.AUDUPDDTE,
f.UNTTYP = m.UNTTYP, f.UNTSTM_NO = m.UNTSTM_NO,
f.UNTIND = f.UNTIND, f.UNQ = m.UNQ,
f.TRNCTL_NO = m.TRNCTL_NO, f.TRN_NO = m.TRN_NO,
f.STAEVT = m.STAEVT, f.SPSDTE = m.SPSDTE,
f.RVRRSN = m.RVRRSN, f.AUDUPDTME = m.AUDUPDTME,
f.RHTTYP = m.RHTTYP, f.ALCADJ = m.ALCADJ,
f.RESFAC = m.RESFAC, f.PRTDTE = m.PRTDTE,
f.POLREF = m.POLREF, f.OUTFAC = m.OUTFAC,
f.OTHBENQTY = m.OTHBENQTY, f.ORIIND = m.ORIIND,
f.ORIDTE = m.ORIDTE, f.INRTYP = m.INRTYP,
f.INRREF = m.INRREF, f.FNDTRNTYP = m.FNDTRNTYP,
f.FNDSUBTYP = m.FNDSUBTYP, f.FNDREF = m.FNDREF,
f.FNDPRC = m.FNDPRC, f.EVTUNQ = m.EVTUNQ,
f.EVTTRN_NO = m.EVTTRN_NO, f.EFVDTE = m.EFVDTE,
f.DUEDTE = m.DUEDTE, f.CTBPCT = m.CTBPCT,
f.CO_REF = m.CO_REF, f.CAL_YR = m.CAL_YR,
f.BONSUBTYP = f.BONSUBTYP, f.BONSTA = m.BONSTA,
f.BONDCL_YR = m.BONDCL_YR, f.BON_YR = m.BON_YR,
f.BENTYP = m.BENTYP, f.BENREF = m.BENREF,
f.BENQTY2 = m.BENQTY2, f.BENQTY1 = m.BENQTY1,
f.AMT = m.AMT, f.ALCRTE = m.ALCRTE
FROM FI700 f
INNER JOIN MERGEDATA_FI700 m ON m.FI700_UNIQUE_ID = f.FI700_UNIQUE_ID
AND m.SSIS_UPDATE_TYPE = 'U'
AND m.SSIS_TIMESTAMP in (SELECT max(mm.SSIS_TIMESTAMP)
FROM MERGEDATA_FI700 mm
WHERE mm.FI700_UNIQUE_ID = m.FI700_UNIQUE_ID
AND mm.SSIS_UPDATE_TYPE = 'U')
Really, I'm just trying to take the latest edit (by the TimeStamp) field, as this will contain all the cumulative edits. I'm pretty sure this can be made to perform better, i.e. somehow integrate the SELECT max(mm.SSIS_TIMESTAMP)
... nested query into the join above it.
Any thoughts?