I have a SQL statement that matches credit amounts to debit amounts which works fine except in cases when there is more than one debit amount for the same value, the code then applies the 1 credit to all the debits of the same amount.
eg. if I have the following
Amount Inv. No.
$200.00 345
$300.00 567
$200.00 129
In the above example using the code below, if I have a credit of $200.00 it will be applied to both inv nos. 345 and 129. I would just like it applied to either 345 OR 129.
SELECT Pos.osamt, Pos.ClientNo, Pos.FirstName, Pos.LastName, Pos.Address1, Pos.Address2, Pos.City, Pos.Country, Pos.TransDate, Pos.InvoiceNo, Pos.PolicyNo, Pos.TransAmt, Pos.TaxAmt, Pos.ReceiptAmt, Pos.Currency
FROM Pos LEFT JOIN Neg ON (Pos.osamt = abs(Neg.osamt)) AND (Pos.ClientNo = Neg.ClientNo)
WHERE (((Neg.osamt) Is Null));
Any help would be appreciated.