UPDATE i00, i13, hota74
SET hota74.p02={my_oldfpa}, 
    hota74.remdate=curdate(), 
    hota74.remtime=curtime(), 
    hota74.remuser='@mass@'
WHERE i00.fpa=i13.p01
   && hota74.p01=i00.pno
   && hota74.p03='{odbcdtos(my_dt1, .t.)}' 
   && hota74.p04='{odbcdtos(my_dt2, .t.)}'
   && i13.p03={my_newfpa}
/*peg_end*/


INSERT INTO hota74
(nr01, p01, p02, p03, p04, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT peg_new_nr01('hota74', 1) as nr01, 
       i00.pno as p01, 
       {my_oldfpa} as p02, 
       '{odbcdtos(my_dt1, .t.)}' as p03, 
       '{odbcdtos(my_dt2, .t.)}' as p04, 
     
       curdate() as remfdate, 
       curtime() as remftime,
       '@mass@'  as remfuser, 
       curdate() as remdate, 
       curtime() as remtime,
       '@mass@'  as remuser
FROM i00
LEFT JOIN i13 ON i00.fpa=i13.p01
LEFT JOIN hota74 ON hota74.p01=i00.pno
                 && hota74.p03='{odbcdtos(my_dt1, .t.)}' 
                 && hota74.p04='{odbcdtos(my_dt2, .t.)}'
WHERE i13.p03={my_newfpa}
   && hota74.nr01 is null;
/*peg_end*/
