Jeowkes
Jeowkes

Reputation: 501

Adding values in a column

Hi i have a DBGrid with an AdoTable dataset, my column headings include "Job ID", "Travel ID" and "Travel Cost". I would like to be able to add the "Travel Cost" values together to create a travel expense total sum. I have also got the following code which filters the Travel ID's that are shown successfully when a Job ID is searched,

DBTravel.DataSource.DataSet.DisableControls;  
DBTravel.DataSource.DataSet.Filtered := False;   
DBTravel.DataSource.DataSet.Filter   := 'Job_ID = ' + edtSearchJobID.Text;    
DBTravel.DataSource.DataSet.Filtered := True;    
DBTravel.DataSource.DataSet.First;   
DBTravel.DataSource.DataSet.EnableControls;   

each Job has many travel expenses, therefore each Job ID has many Travel ID's and also Travel Costs, ultimately i would like the Travel expense total sum to be the addition of only those "travel cost" values which are displayed through the filter, i.e the travel expense total sum includes only the "Travel Costs" with Job ID that equals edtSearchJobID.Text and is displayed in the dbgrid following the search. thanks

Upvotes: 4

Views: 1269

Answers (1)

kobik
kobik

Reputation: 21252

You should use Aggregates and Grouping to sum Travel Costs filtered by Job ID:

Upvotes: 6

Related Questions