SELECT max(if( ifnull(tabl01.p106, 0)=1, ifnull(tabl01.nr01_1, 0), 0)) as nr01, 
       sum(ifnull(tabl01.p106, 0)) as p01, 
       ifnull(erpa80.p13, 0) as a80p13,
       ifnull(erpa80.p08, 0) as a80p08
FROM erpa80
LEFT JOIN (   /* transactions */
    {peg_str}
) as tabl01 ON erpa80.nr01=tabl01.nr01
            && tabl01.p107=0
            && tabl01.p108=0
WHERE erpa80.nr01={pub_arr1[1]}
group by erpa80.nr01;
       