update d65,           
        (SELECT d65.nr01 as nr01, 
                d65.p300 as p300, 
                ifnull( (select d99102_in.p300
                         from d99102 as d99102_in
                         where d99102_in.tbl='d65'
                            && d99102_in.tbl_nr01=d65.nr01
                         order by d99102_in.dt desc, d99102_in.tm desc
                         limit 1), 0) as dp300
                         
         FROM d65
         WHERE d65.p00>={pub_arr1[1]}
            && d65.p00<={pub_arr1[2]}
        ) as tbl01
set d65.p300=tbl01.dp300, 
    d65.remdate=curdate(), 
    d65.remtime=curtime(), 
    d65.remuser='{user_pswd}'
where d65.p300<>tbl01.dp300
   && d65.nr01=tbl01.nr01;
/*peg_end*/