zOs/SQL/PDBGENEX

set current schema = RR2xx;
insert into A540769.tacct_general
    with w  as
    (  select
           case
           when corrName like  'MFT15%'       then 'mfLoad'
           when corrName like  'MFT18%'       then 'mfPflege'
           when connect_id like 'MFT56%'      then 'mfTurnover'
           when corrName =     'MFT3100P'     then 'mfAuswertung'
           when corrName like 'NIT15%'        then 'ni150load'
           when corrName like 'NIT16%' and log_recs_written > 30
                                              then 'ni250Load'
           when CONNECT_ID like 'NIT17%'      then 'ni150InsEmpClu'
           when CONNECT_ID like 'NIT18%' or plan_name = 'NI5392'
                                              then 'ni250InsNoPos'
           when plan_name = 'NI5310'          then 'ni250Update'
           when plan_name = 'NI5340'          then 'ni250Insert'
           else                                    '' end id,
           left(current schema, 3) rz,
           current date insDate,
           g.*
         from tacct_general g
    ) , sel as
    ( select * from w where id <> ''
    )
      select * from sel
          where not exists (select 1
              from A540769.TACCT_GENERAL o
              where o.id = sel.id and o.rz = sel.rz
                  and o.timestamp = sel.timestamp
                  and o.subsystem_id = sel.subsystem_id
            )
;