Best way to get multiple aggregates?

Posts   
 
    
slade52
User
Posts: 46
Joined: 15-Aug-2007
# Posted on: 18-Nov-2007 04:38:54   

Hi,

Relative newbie needs to check something. Is this:


ResultsetFields fields = new ResultsetFields(10);
fields.DefineField(AgedBalanceFields.TotalDebt, 0, AggregateFunction.Sum);
fields.DefineField(AgedBalanceFields.BilledThisMonth, 1, AggregateFunction.Sum);
fields.DefineField(AgedBalanceFields.DueThisMonth, 2, AggregateFunction.Sum);
fields.DefineField(AgedBalanceFields.Overdue1Month, 3, AggregateFunction.Sum);
fields.DefineField(AgedBalanceFields.Overdue2Months, 4, AggregateFunction.Sum);
fields.DefineField(AgedBalanceFields.Overdue3Months, 5, AggregateFunction.Sum);
fields.DefineField(AgedBalanceFields.Overdue4Months, 6, AggregateFunction.Sum);
fields.DefineField(AgedBalanceFields.Retentions, 7, AggregateFunction.Sum);
fields.DefineField(AgedBalanceFields.Unallocated, 8, AggregateFunction.Sum);
fields.DefineField(AgedBalanceFields.CreditLimit, 9, AggregateFunction.Sum);

PredicateExpression groupFilter = new PredicateExpression();
groupFilter.Add(new FieldCompareValuePredicate(AgedBalanceFields.DebtorGroupUid, ComparisonOperator.Equal, (Guid)(dd.DebtorGroupUid)));
groupFilter.Add(new FieldCompareValuePredicate(AgedBalanceFields.BalanceYear, ComparisonOperator.Equal, BalanceYear));
groupFilter.Add(new FieldCompareValuePredicate(AgedBalanceFields.BalanceMonth, ComparisonOperator.Equal, BalanceMonth));

DataTable dynamicList = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dynamicList, 0, null, groupFilter, null, false, null, null, 0, 0);

... the best way to achieve this:


SELECT
    SUM(TotalDebt),
    SUM(BilledThisMonth),
    SUM(DueThisMonth),
    SUM(Overdue1Month),
    SUM(Overdue2Months),
    SUM(Overdue3Months),
    SUM(Overdue4Months),
    SUM(Unallocated),
    SUM(Retentions),
    SUM(CreditLimit)
FROM AgedBalance
WHERE DebtorGroupUID = @DebtorGroupUID
AND BalanceYear = @BalanceYear
AND BalanceMonth = @BalanceMonth

Please assume the various referenced variables are defined elsewhere.

[edit: LLBLGen 2.5, SelfServicing]

Thanks in advance Mike

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Nov-2007 21:47:07   

Hi Mike,

Your code looks good so far. That code indeed reproduces the SQL you posted. Are you looking for another way to write such code?

David Elizondo | LLBLGen Support Team
slade52
User
Posts: 46
Joined: 15-Aug-2007
# Posted on: 18-Nov-2007 22:07:14   

Hi David, thanks for your response.

I was looking for any way to write that code, and what I posted seemed to me to be the best approach. I'm quite new to LLBLGen so just wanted to check (the application is still a couple of days away from a full test).

Thanks again Regards Mike