select sd.id, sum(sd2.tamount) from storedocuments sd join storedocuments2 sd2 on sd2.parent_id=sd.id where sd.documenttype='21' and sd.docdate$date=:DocDate and (select count(*) from Relations rel where (rel.Rel_Def = 1618) and (rel.LeftSide_ID = sd.ID)) = 0 and (select count(*) from Relations rel where (rel.Rel_Def = 1650) and (rel.RightSide_ID = sd.ID)) = 0 and sd2.quantity<>0 and ((coalesce(:BusOrder_ID, '0000000000') <> '0000000000') or (coalesce(:BusTransaction_ID, '0000000000') <> '0000000000') or (coalesce(:BusProject_ID, '0000000000') <> '0000000000')) and ((coalesce(sd2.BusOrder_ID, '0000000000') = coalesce(:BusOrder_ID, '0000000000')) or (coalesce(:BusOrder_ID, '0000000000') = '0000000000')) and ((coalesce(sd2.BusTransaction_ID, '0000000000') = coalesce(:BusTransaction_ID, '0000000000')) or (coalesce(:BusTransaction_ID, '0000000000') = '0000000000')) and ((coalesce(sd2.BusProject_ID, '0000000000') = coalesce(:BusProject_ID, '0000000000')) or (coalesce(:BusProject_ID, '0000000000') = '0000000000')) group by sd.id
Generated by ABRA Software a.s. 27.10.2021 16:35:32