update i10, z_i10_std as imp01
set i10.p01=imp01.p01, 
    i10.p02=imp01.p02, 
    
    i10.remdate=curdate(), 
    i10.remtime=curtime(), 
    i10.remuser='{user_pswd}@std_tables'
     
where i10.nr01=imp01.nr01
   && (    i10.p01<>imp01.p01 
        || i10.p02<>imp01.p02 
      );
/*peg_end*/

insert into i10
(nr01, p01, p02, p03, p04, p05, p101, p102, p103, p105, p106, is_std, p300,
remfdate, remftime, remfuser, remdate, remtime, remuser)
select imp01.nr01, 
       imp01.p01, 
       imp01.p02, 
       imp01.p03, 
       imp01.p04, 
       imp01.p05, 
       imp01.p101, 
       imp01.p102, 
       imp01.p103, 
       imp01.p105, 
       imp01.p106, 
       imp01.is_std, 
       {if(my_exnostd, '0', '1')} as p300, 
       
       curdate() as remfdate, 
       curtime() as remftime, 
       '{user_pswd}@std_tables' as remfuser, 
       curdate() as remdate, 
       curtime() as remtime, 
       '{user_pswd}@std_tables' as remuser 
from z_i10_std as imp01
left join i10 on i10.nr01=imp01.nr01
where i10.nr01 is null;
/*peg_end*/

