I need to make some aggregates using TClientdataset. In SQL these aggregates can be done with script like this :
Select Sum(column1) from table1 where Date_Column < Date_Value
Because I need more speed during a very long process and a very slow network, I want to use in-memory aggregates instead of using sql . My idea is to add an aggregate to the ClientDataset with Expression like this:
Sum(column1)
And make Date_Column index, then filter the clientdataset like this:
myClientdataset.SetRang([value1],[value2]);
I was expecting to see the aggregate result of this range, but, unfortunately the aggregate ignore the range and keep giving the result of all records!
So, my question is: how I can achieve this in TClientdataset? Or, do you have any other idea how to do ranged-aggregates in memory?
Maybe this link will be helpful: Grouping and Aggregates
Edit:
I think i've got it, it took me quite time and it was a frustrating experience;)
I've made a sample project.
First, an aggregate without filtering:
Second, an aggregate after presing a button:
Is this is the effect which you wanted?
Please note that I was not able to achieve this efect with usage of SetRange(), I've used Filter property instead.
How to achieve:
My code after pressing a button:
Please note that in Filter you can easly change condition to achieve the same result as for the SetRange. However, I've read that SetRange is faster in filtering data.
Hope it helps:)