SELECT * FROM Invoices WHERE inv_pk IN (SELECT inv_pk FROM (SELECT a.inv_pk, a.inv_debt, SUM(b.Inv_debt) as previous FROM invoices A LEFT JOIN invoices B ON A.inv_debno = B.inv_Debno AND A.inv_DateTime > b.inv_DateTime WHERE inv_debno = ?nMyDebno GROUP BY a.inv_pk, a.inv_debt HAVING SUM(b.Inv_debt) < ?nTreshhold ) AS a WHERE ISNULL(inv_debt, 0) + Previous > ?nTreshhold)Now I did not test the above and it probably needs some tweaking before it works as intended. Now besides this solution is really much more difficult than the VFP version, it is performing unneccesary tasks as well, as it is accumulating a carthesian product and filtering it. It is VERY resource intensive.