UPDATE T1 SET T1.Amount = ( SELECT SUM(T2.Amount) * -1 FROM TblAccounting T2 WHERE T2.VoucherNo = T1.VoucherNo AND T2.AcCode = 10000 AND T2.Id > T1.Id -- Selecting rows "below" based on Id ) FROM TblAccounting T1 WHERE T1.Amount is null and type='CustomerReceipt'