/***************************
       d00 => d64
***************************/       
insert into d64    
(nr01, p00, p001, p01, p02, p05, p06, pd100, 
remfdate, remftime, remfuser, remdate, remtime, remuser) 
SELECT peg_new_nr01('d64', 1) as nr01, 
       tbl01.p00 as p00, 
       tbl01.p001 as p001, 
       peg_abschr(tbl01.p01, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') as p01, 
       tbl01.p02 as p02, 
       tbl01.p05 as p05, 
       tbl01.p06 as p06, 
       tbl01.pd100 as pd100, 
       curdate() as remfdate, 
       curtime() as remftime, 
       '{user_pswd}' as remfuser, 
       curdate() as remdate, 
       curtime() as remtime, 
       '{user_pswd}' as remuser 
       
FROM 
(
      select  d00.nr01 as p00,    
              d00.p8 as p001,    
              peg_abschr(d00.p8, concat("`!@#$%^&*()_+-=~{[}]|\;:()' <,>.?/", '"')) as p01,    
              1 as p02,    
              1 as p05,    
              1 as p06,    
              'phone-01' as pd100 
       from d00    
       LEFT JOIN d64 ON d64.p00=d00.nr01
                     && d64.pd100='phone-01'
       WHERE d00.p8<>''    
          && d64.nr01 is null

       UNION ALL    

      select  d00.nr01 as p00,    
              d00.p9 as p001,    
              peg_abschr(d00.p9, concat("`!@#$%^&*()_+-=~{[}]|\;:()' <,>.?/", '"')) as p01,    
              1 as p02,    
              1 as p05,    
              2 as p06,    
              'phone-02' as pd100 
       from d00    
       LEFT JOIN d64 ON d64.p00=d00.nr01
                     && d64.pd100='phone-02'
       WHERE d00.p9<>''    
          && d64.nr01 is null

       UNION ALL   
 
       select d00.nr01 as p00,    
              d00.p10 as p001,    
              peg_abschr(d00.p10, concat("`!@#$%^&*()_+-=~{[}]|\;:()' <,>.?/", '"')) as p01,    
              2 as p02,    
              1 as p05,    
              3 as p06,    
              'fax-01' as pd100 
       from d00    
       LEFT JOIN d64 ON d64.p00=d00.nr01
                     && d64.pd100='fax-01'
       WHERE d00.p10<>''    
          && d64.nr01 is null
) as tbl01;
/*peg_end*/

/***************************
       d00 => d65
***************************/       
insert into d65    
(nr01, p00, p01, p02, p05, pd100, 
remfdate, remftime, remfuser, remdate, remtime, remuser) 
select peg_new_nr01('d65', 1) as nr01,    
       d00.nr01 as p00,    
       lower(d00.p11) as p11,    
       1 as p02,    
       1 as p05,    
       'email-01' as pd100, 
       curdate() as remfdate, 
       curtime() as remftime, 
       '{user_pswd}' as remfuser, 
       curdate() as remdate, 
       curtime() as remtime, 
       '{user_pswd}' as remuser 
from d00
left join  d65 on d65.p00=d00.nr01
               && d65.pd100='email-01'    
WHERE d00.p11<>''
   && d65.nr01 is null;
/*peg_end*/
