/********************************
      tran01
********************************/
/* t01->tran01 */
INSERT INTO tran01 
(nr01, p301, p014, p017, sp01, p00, p103, p104, p61,
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT t01.p302 as nr01, 
       t01.p02  as p301, 
       t01.p02  as p014, 
       t01.p02t as p017, 
       1 as sp01, 
       '*#*' as p00, 
       t01.p06 as p103,
       t01.p05 as p104, 
       ifnull(a01.nr01, 0) as p61, 
       t01.remfdate as remfdate, 
       t01.remftime as remftime, 
       t01.remfuser as remfuser, 
       curdate()    as remdate, 
       curtime()    as remtime, 
       '{user_pswd}' as remuser 
FROM t01
LEFT JOIN tran01 ON tran01.nr01=t01.p302
LEFT JOIN a01 ON a01.p21=t01.p01
where t01.p303 in (11, 12, 14, 15, 16)
   && tran01.nr01 is null
GROUP BY t01.p302;   
/*peg_end*/

/* tran02->tran01 */
INSERT INTO tran01 
(nr01, p301, p014, p017, sp01, p00, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT tran02.p00 as nr01, 
       tran02.remdate as p301, 
       tran02.remdate as p014, 
       tran02.remtime as p017, 
       1 as sp01, 
       '*#*' as p00, 
       tran02.remfdate as remfdate, 
       tran02.remftime as remftime, 
       tran02.remfuser as remfuser, 
       curdate()    as remdate, 
       curtime()    as remtime, 
       '{user_pswd}' as remuser 
FROM tran02
LEFT JOIN tran01 ON tran01.nr01=tran02.p00
where tran01.nr01 is null
GROUP BY tran02.p00;   
/*peg_end*/