Hi,
We are using sql server 2012. This query is used by financial applications. Each client has multiple accounts. There will be multiple transactions happening on each account (like deposit, withdrawal, sale money, internal transfers etc).
Eg:
TransactionID | Type | Incoming Account# | Outgoing Account # | Date | Amount |
1000 | Deposit | 1101 | 01/01/2014 7:30 AM | 500.00 | |
1001 | Withdrawal | 1101 | 01/02/2014 7:00 AM | 300.00 | |
1002 | Internal Transfer | 1101 | 1102 | 01/02/2014 8:00 AM | 100.00 |
1103 | Withdrawal | 1102 | 01/04/2014 9:00 AM | 50.00 | |
This is just sample to get feel. I need to take so many other criteria into account when checking whether particular account has enough amount. All the above transactions belong to 1 client.
In above table, account 1101 got money 600/- but 300.00 got withdrawn. So, account has enough money
What I was doing in a loop call another stored procedure and pass transaction for calculations based on criteria and finally come up with whether account has sufficient amount and mark it in a table for that account. Next send next transaction to the stored proc in a loop and check the amount sufficiency. In the above example, I go in loop and call another stored procedure for account 1101 3 times.
So, it is taking long time and we are getting timeout error. Is there any other efficient way of handling this for a particular date range.
I appreciate your response.
Thanks,
Spunny