select i00_tbl01.*
from  ( 
         {peg_str1} 
       ) as i00_tbl01
LEFT JOIN i01 ON i01.p01=i00_tbl01.pno
              && i01.p013>=cast( '{odbcdtos(ns_dat1)}' as date)
              && i01.p013<=cast( '{odbcdtos(ns_dat2)}' as date)
              && i01.p014='{ns_log}'
WHERE i01.nr01 is not null
GROUP BY i00_tbl01.pno