select 1001 as SOURCETYPE, PURCHASEINVOICELINE.ITSID as SOURCEID, 1 as SOURCEOWNERTYPE, PURCHASEINVOICE.ITSID as SOURCEOWNERID, PURCHASEINVOICE.ITSDATE, THEREST
from PURCHASEINVOICELINE
join PURCHASEINVOICE on PURCHASEINVOICE.ITSID = PURCHASEINVOICELINE.ITSOWNER
where PURCHASEINVOICELINE.REVERSEDID is null and THEREST>0 and INVITEM=:INVITEM and UNITOFMEASURE=:UNITOFMEASURE

