Jump to content
Sign in to follow this  
Henry Olive

Getting SUM of a Calculated Field

Recommended Posts

I wish everyone a healthy day.
How can i get get SUM of a calculated field ?
I have a TOTAL field which is calculated.

I want to get SUM of TOTAL and write the result in a Label or DBtext
p.s : I know i can do it While Not CDS1.Eof ...

I wonder is there a better way

Thank You

Edited by Henry Olive

Share this post


Link to post
Guest

You need to provide more information. 

Share this post


Link to post

Thank you so much Dany,

var MyCalcField : Double

(CDS1 =Client Dataset;)

 

MyCalcField :=(CDS1A.asFloat + CDS1B.asFloat + CDS1C.asFloat) -

                        (CDS1D.asFloat + CDS1E.asFloat);

Now i want to get Sum of MyCalcField (Total result of MyCalField)

and I want to do this process in Delphi

 

CDS1 View :

EmpName  MyCalcField 

AAA...........................5,000

BBB............................6,000

 

I need to get 5000 + 6000 = *11,000 result*

I know i can make this with a SQL and i can make scan the CDS1

(While not CDS1.Eof do ... )

I thought may be there could be a better way to do this in Delphi

 

 

 

 

Share this post


Link to post
Guest

I use a different CDS.

 

Generally Grids and "multi record" controls providing sums or summary functionality also loop through all records, if it would not it would not be able to load the records.

Since you indicate a ClientDataSet, SQL would probably not yield a more performant result (it's executed locally). It could (if the CDS has that functionality) provide for better looking code depending on your background.

KbmMemTable provides such functionality i do not know about TClientDataset.

 

If it where a RDBMS connection, depending on the number of records, i sometimes use two requests, one for all the rows and one for an aggregated sum.

But whether this is better/faster/... is a question of a lot of parameters.

 

HTH,

 

/D

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×