
create table tmp_contract (cnt_contract_key NUMBER(10));

insert into tmp_contract (cnt_contract_key)
select distinct  cnt_contract_key from fac_tracking t, cnt_contract c where fac_tracking_datum > sysdate - 3
and fac_srtnotificatie_key = 523
and t.prs_perslid_key = 69
and fac_tracking_refkey = cnt_contract_key

update cnt_contract c set
cnt_contract_status = 3,
cnt_contract_teverzenden = null
where cnt_contract_key in (select cnt_contract_key from tmp_contract)

insert into fac_tracking (fac_tracking_datum, fac_tracking_refkey, prs_perslid_key, fac_tracking_oms, fac_srtnotificatie_key)
select sysdate, cnt_contract_key, 69, 'Contract ter goedkeuring [AADS#31224]', 521 from tmp_contract

drop table tmp_contract