I need to create a stored procedure to check every record in a table sorted by SalesRepNo and SalesID. There is a field called "SalesAmt" that may be positive or negative value and another field called "RunBalance" that holds a running total. The records are sorted by SalesRepNo, SalesID. I want a stored procdure to loop through all records and verify that the running balance is correct. If it's not I need to fix and send record to a log.
fields:salesRepNo, SalesID, SalesAmt, RunBalalnce
I am looking for a starting point on how to do this. What the stored proc should look like.