SELECT *
FROM
(
   SELECT 0 as p00,
          hota40.p101 as p01,
          concat(hota40.p02, ' ', ifnull(hota03.p02, ''))  as p02, 
          hota40.p106-hota40.p114 as p03
   FROM hota40
   LEFT JOIN hota03 ON hota03.p01=hota40.p04
   WHERE hota40.p01={my_hotar04[1]}
/*      && hota40.p101<='{odbcdtos(np01)}'
*/      
   UNION ALL   
      
   SELECT 1 as p00, 
          hota41.p101 as p01,
          ifnull(hota03.p02, '')  as p02, 
          hota41.p104 as p03
   FROM hota41
   LEFT JOIN hota03 ON hota03.p01=hota41.p02
   WHERE hota41.p01={my_hotar04[1]}
/*      && hota41.p101<='{odbcdtos(np01)}'
*/
) as tbl01
WHERE p03<>0
ORDER BY p01, p00;
