/****************************
   i00.p3011 -> i02
***************************/
insert into i02
(nr01, p00, p01, p02, p03, tax, p04, p05, 
remdate, remtime, remuser, remfdate, remftime, remfuser )
select peg_new_nr01('i02', 1) as nr01, 
       i00.pno as p00, 
       1 as p01, 
       i00.p3011 as p02,
       '' as p03, 
       1 as tax, 
       curdate() as p04, 
       curtime() as p05, 
       
       curdate() as remdate, 
       curtime() as remtime, 
       '{user_pswd}' as remuser, 
       curdate() as remfdate, 
       curtime() as remftime, 
       '{user_pswd}' as remfuser 
FROM i00
LEFT JOIN i02 ON i00.pno=i02.p00
              && i00.p3011=i02.p02
WHERE i00.p3011<>''
   && i02.nr01 is null;
/*peg_end*/

/****************************
   i00.p3012 -> i02
***************************/
insert into i02
(nr01, p00, p01, p02, p03, tax, p04, p05, 
remdate, remtime, remuser, remfdate, remftime, remfuser )
select peg_new_nr01('i02', 1) as nr01, 
       i00.pno as p00, 
       2 as p01, 
       i00.p3012 as p02,
       '' as p03, 
       2 as tax, 
       curdate() as p04, 
       curtime() as p05, 
       
       curdate() as remdate, 
       curtime() as remtime, 
       '{user_pswd}' as remuser, 
       curdate() as remfdate, 
       curtime() as remftime, 
       '{user_pswd}' as remfuser 
FROM i00
LEFT JOIN i02 ON i00.pno=i02.p00
              && i00.p3011=i02.p02
WHERE i00.p3012<>''
   && i02.nr01 is null;
/*peg_end*/

       