/********************************
      a55
********************************/
/* t01->a55 */
INSERT INTO a55 
(nr01, p01, p02, p03, p08, p06, p010, p011, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT t01.p302 as nr01, 
       t01.p02 as p01, 
       t01.p02t as p02, 
       ifnull(a01.nr01, 0) as p03, 
       1 as p08, 
       '*#*' as p06, 
       t01.p05 as p010, 
       t01.p06 as p011, 
       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 a55 ON a55.nr01=t01.p302
LEFT JOIN a01 ON a01.P21=t01.p01
where t01.p303 IN (2, 4)
   && a55.nr01 is null
GROUP BY t01.p302;   
/*peg_end*/


/* i01->a55 */
INSERT INTO a55 
(nr01, p01, p02, p03, p08, p06, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT i01.p06 as nr01, 
       i01.p013 as p01, 
       i01.p013t as p02,
       ifnull(a01.nr01, 0) as p03, 
       1 as p08, 
       '*#*' as p06, 
       i01.remfdate as remfdate, 
       i01.remftime as remftime, 
       i01.remfuser as remfuser, 
       curdate()    as remdate, 
       curtime()    as remtime, 
       '{user_pswd}' as remuser 
FROM i01
LEFT JOIN a55 ON a55.nr01=i01.p06
LEFT JOIN a01 ON a01.p21=i01.p014
where i01.p07=2
   && a55.nr01 is null
GROUP BY i01.p06;   
/*peg_end*/


/********************************
      a56
********************************/
/* t01->a56 */
INSERT INTO a56 
(nr01, p01, p02, p03, p08, p06, p010, p011, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT t01.p302 as nr01, 
       t01.p02 as p01, 
       t01.p02t as p02, 
       ifnull(a00.nr01, 0) as p03, 
       1 as p08, 
       '*#*' as p06, 
       t01.p05 as p010, 
       t01.p06 as p011, 
       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 a56 ON a56.nr01=t01.p302
LEFT JOIN a00 ON a00.P21=t01.p01
where t01.p303 IN (1, 3)
   && a56.nr01 is null
GROUP BY t01.p302;   
/*peg_end*/


/* i01->a56 */
INSERT INTO a56 
(nr01, p01, p02, p03, p08, p06, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT i01.p06 as nr01, 
       i01.p013 as p01, 
       i01.p013t as p02, 
       ifnull(a00.nr01, 0) as p03, 
       1 as p08, 
       '*#*' as p06, 
       i01.remfdate as remfdate, 
       i01.remftime as remftime, 
       i01.remfuser as remfuser, 
       curdate()    as remdate, 
       curtime()    as remtime, 
       '{user_pswd}' as remuser 
FROM i01
LEFT JOIN a56 ON a56.nr01=i01.p06
LEFT JOIN a00 ON a00.p21=i01.p014
where i01.p07=1
   && a56.nr01 is null
GROUP BY i01.p06;   
/*peg_end*/


/********************************
      a60
********************************/
/* i01->a60 */
INSERT INTO a60 
(nr01, p01, p08, p06, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT i01.p06 as nr01, 
       i01.p013 as p01, 
       1 as p08, 
       '*#*' as p06, 
       i01.remfdate as remfdate, 
       i01.remftime as remftime, 
       i01.remfuser as remfuser, 
       curdate()    as remdate, 
       curtime()    as remtime, 
       '{user_pswd}' as remuser 
FROM i01
LEFT JOIN a60 ON a60.nr01=i01.p06
where i01.p07=3
   && a60.nr01 is null
GROUP BY i01.p06;   
/*peg_end*/


/********************************
      t08
********************************/
/* t01->t08 */
INSERT INTO t08 
(nr01, p01, p03, p08, p06, p010,
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT t01.p302 as nr01, 
       t01.p02 as p01, 
       t01.p01 as p03, 
       1 as p08, 
       '*#*' as p06, 
       t01.p05 as p010, 
       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 t08 ON t08.nr01=t01.p302
where t01.p303 =6
   && t08.nr01 is null
GROUP BY t01.p302;   
/*peg_end*/

/* t08->t08 */
INSERT INTO t08 
(nr01, p01, p08, p06, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
SELECT t09.p00 as nr01, 
       t09.remdate as p01, 
       1 as p08, 
       '*#*' as p06, 
       t09.remfdate as remfdate, 
       t09.remftime as remftime, 
       t09.remfuser as remfuser, 
       curdate()    as remdate, 
       curtime()    as remtime, 
       '{user_pswd}' as remuser 
FROM t09
LEFT JOIN t08 ON t08.nr01=t09.p00
where t08.nr01 is null
GROUP BY t09.p00;   
/*peg_end*/



