Solved

correct Balance

Posted on 2012-03-31
3
554 Views
Last Modified: 2012-04-24
I've transaction table of money movement (credit, Debit) for my customer. the field Balance shows the balance after each operation (deposit , withdraw). sometimes, there  is an incorrect value in balance field. therefore, I'd made correct balance procedure by using for loop. this procedure takes long time to correct the balance. is there an other way to do that without for loop. (faster than for loop).
balance.png
0
Comment
Question by:khaledsalem
3 Comments
 
LVL 9

Accepted Solution

by:
macarrillo1 earned 250 total points
ID: 37791935
You could change the table(s) that are doing the calculation to use indexes for the fields used in the where portion of your query.
In other words create an index(es) on your table to optimize your query.
0
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 250 total points
ID: 37792563
In your place I wouldn't create and store column balance in my database, because each time you amend Credit or Debit it requires the entire table to be updated.
This can be done by creating  a CalcField which is going to show a calculation of "Total Cr - Total Dr" of each line for each particular customer "compID".
You are going to have loop if you need the calculation for each record (every line shows the balance) by running a query to calculate the balance from the first record up to the current one.
There might be loop but the loop you have here runs only to calculate and show but not to iterate through your entire records and amend.
0
 
LVL 25

Expert Comment

by:TempDBA
ID: 37792876
My doubt is why is it showing incorrect data when the calculation part is correct. Can you put the query you are using?
And what isolation level you are using for?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now