select pt.id
from ProductionTasks pt
inner join storedocuments2 sd2 on (sd2.productiontask_id = pt.id)
inner join storedocuments sd on (sd2.parent_id = sd.id)
where ((sd.documenttype = '27') or (sd.documenttype = '29'))
and pt.ownertype = 1
and pt.id = :OBJID
group by pt.id, sd2.storecard_id
having
(sum(case when(sd.documenttype = '27') then sd2.quantity else -sd2.quantity end)-
(select coalesce(sum(pt2.materialquantity), 0)
from productiontasks2 pt2
where pt2.parent_id = pt.id
and pt2.material_id = sd2.storecard_id) <> 0
)
Generated by ABRA Software a.s. 27.10.2021 16:34:49