insert into q24
(nr01, p01, p02, p03, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
select peg_new_nr01('q24', 1) as nr01, 
       '{nt_p02}' as p01, 
       q24_1.p02 as p02, 
       q24_1.p03 as p03, 
       
       curdate() as remfdate, 
       curtime() as remftime, 
       '{user_pswd}' as remfuser, 
       curdate() as remdate, 
       curtime() as remtime, 
       '{user_pswd}' as remuser 
from q24 as q24_1
left join q24 as q24_2 ON q24_2.p02=q24_1.p02
              && q24_2.p01='{nt_p02}'
where q24_1.p01='{nt_p01}'         
   && q24_2.nr01 is null;
/*peg_end*/        