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

insert into d23
(nr01, p01, p02, ep02, p300, tax, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
select peg_new_nr01('d23', 1) as nr01, 
       imp01.p01, 
       imp01.p02, 
       imp01.ep02, 
       imp01.p300, 
       imp01.tax, 
       
       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_d23_std as imp01
left join d23 on d23.p01=imp01.p01
where d23.nr01 is null;
/*peg_end*/