FernandoLorival
Starting Member
19 Posts |
Posted - 2013-09-27 : 12:48:10
|
Hi all,I have a financial table that holds financial transaction, one of the fields is Balance. When a transaction is posted that field is populated with an amount, when the client pays that amount or a fraction of the amount, another transaction is created (row) that will deduct from the initial balance. This happens until the balance is 0.Now, I need a report that shows only my open balances, basically the last transaction posted against the client.Here's my code example:DECLARE @TEMP1 TABLE (ClientNo INT, TransactionID INT, TransAmount INT, Balance INT);INSERT @TEMP1VALUES (1, 1, 123, 123),(1, 2, -123, 0), (2, 1, 500, 500),(3, 1, 45000, 45000),(4, 1, 45, 45),(5, 1, -234, -234),(5, 2, 123, -111),(6, 1, 234234, 234234) In this case I would like to get the information for Client 2,3,4,5 and 6.NOTE: For client 5 I only want to show the last line, open balance -111.Thank you all for your time. |
|