Delphi: how to aggregate only ranked records in TClientDataset?

I need to do some aggregates using TClientdataset . In SQL, these aggregates can be executed using a script as follows:

Select Sum(column1) from table1 where Date_Column < Date_Value

Since I need more speed during a very long process and a very slow network, I want to use aggregates in memory instead of using sql. My idea is to add an aggregate to the ClientDataset with an expression as follows:

Sum(column1)

And make the Date_Column index, then filter the clientdataset file like this:

myClientdataset.SetRang([value1],[value2]);

I expected to see the cumulative result of this range, but, unfortunately, the aggregate ignores the range and continues to give the result of all the records!

, : TClientdataset? - , ?

+5
1

, :

Edit:

, , , ;)

.

-, :

Aggregate without filtering

-, :

Aggregate with filtering

, ?

: SetRange(), Filter.

:

  • - , GroupingLevel 0.
  • TClientDataset.IndexName.
  • GroupingLevel = 0 Expression, SUM (YourFieldName), SUM (Population).
  • IndexName , .
  • ( , , ).

:

  cdsMain.Filter := 'Population <= 100';
  cdsMain.Filtered := True;
  if not VarIsNull(cdsMain.Aggregates[0].Value) then
    lblAggregatedPopulation.Caption := 'Aggregated population: ' + IntToStr(cdsMain.Aggregates[0].Value);

, Filter , SetRange. , , SetRange .

, :)

+7

All Articles