insert into {p_mydt10tbl1}
(tbl, tbl_nr01, p00, p01, p03,  p06, p07, p08d, p08t,
currency, exchrate, 
series, aa, issuedate, issuetime, invtype, paytype, 
is_country, is_vat, is_name, is_address, is_city, is_zip, 
cp_country, cp_vat, cp_name, cp_address, cp_city, cp_zip)

SELECT tbl as tbl, 
       tbl_nr01 as tbl_nr01, 
       p00 as p00, 
       p01 as p01, 
       p03 as p03, 
       p06 as p06, 
       p07 as p07, 
       p08d as p08d, 
       p08t as p08t, 
       currency as currency, 
       exchrate as exchrate, 
       series as series, 
       peg_abschr(peg_abschr(aa, ''), "ABCDEFGHIJKLMNOPQRSTUVWXYZ~`@#$%^&*()-+ /?.>,<'") as aa, 
       issuedate as issuedate, 
       issuetime as issuetime, 
       invtype as invtype, 
       paytype as paytype, 
       
       ''             as is_country,
       '{nt_p101[1]}' as is_vat, 
       '{nt_p101[2]}' as is_name, 
       '{nt_p101[3]}' as is_address, 
       '{nt_p101[4]}' as is_city, 
       '{nt_p101[5]}' as is_zip,
       a_country as cp_country,
       a_vat     as cp_vat, 
       a_name    as cp_name, 
       a_address as cp_address, 
       a_city    as cp_city, 
       a_zip     as cp_zip 

FROM
(
      /***********************************************
             Παραστατικά προς αποστολή
             q30.nr01=620036
      ***********************************************/
      (
      SELECT 'c78' as tbl, 
             c78.nr01 as tbl_nr01, 
             1 as p00,
             1 as p01,
             0 as p03, 
             ifnull(a01.p45, 0) as p06, 
             ifnull(c77.p03, 0) as p07, 
             c78.remdate as p08d, 
             c78.remtime as p08t,             
             '' as currency, 
             0 as exchrate,
       
             /**στοιχεία παραστατικού*/
             '' as series, 
             c78.p03 as aa, 
             c78.p02 as issuedate, 
             c78.p02t as issuetime, 
             ifnull(mydt50.p00, '') as invtype, 
             
             /**paytype**/           
             ifnull( (select q31_in.p05
                      from q31 as q31_in
                      where q31_in.p01=620044
                         && q31_in.p03=c78.p08
                      limit 1), '') as paytype,
             
             /*αντισυμβαλλόμενος*/
             ifnull(a01.p4_1, '') as a_country, 
             ifnull(a01.p20, '') as a_vat, 
             ifnull(a01.p19, '') as a_name, 
             ifnull(a01.p4, '') as a_address, 
             concat( ifnull(concat(d22.p02, ' '), ''), 
                     ifnull(concat(a01.p5, ' '), ''),
                     ifnull(concat(a01.p6, ' '), '')
                   ) as a_city, 
             ifnull(a01.p7, '') as a_zip 
      FROM q31
      LEFT JOIN c77 ON q31.p03=c77.nr01
      LEFT JOIN c78 ON c78.p01=c77.nr01
                    && c78.p02>=cast('{odbcdtos(nt_p01)}' as date)
                    && c78.p02<=cast('{odbcdtos(nt_p02)}' as date)
                    && c78.remdate>=cast('{odbcdtos(nt_p07d)}' as date)
                    && c78.remdate<=cast('{odbcdtos(nt_p08d)}' as date)
                    && concat(c78.remdate, c78.remtime)>=concat(cast('{odbcdtos(nt_p07d)}' as date), '{nt_p07t}')
                    && concat(c78.remdate, c78.remtime)<=concat(cast('{odbcdtos(nt_p08d)}' as date), '{nt_p08t}')
                    && c78.p100>={nt_p03}
                    && c78.p100<={nt_p04}
      LEFT JOIN mydt50 ON mydt50.p00=q31.p05
      LEFT JOIN a01 ON a01.nr01=c78.p503
      LEFT JOIN d22 ON d22.p01=a01.p4_3
      WHERE q31.p01=620036
         && c78.nr01 is not null
         && c77.nr01 is not null
         && {p_mydt10where} 
         && {nt_napost}=1
      GROUP BY c78.nr01
      )

) as tbl01;   
         
       