Documentation: Aggregate Functions Max

Posts   
 
    
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 27-May-2024 15:47:42   

Query Spec, version 5.9.6 Sql Server Online documentation says:

Max Calculates the max value for field MAX(field) Works on numeric fields (decimal / int / float / byte / etc.) only

For me seems to work on other column types like string. I haven't tested date yet but I hope it works. This may be true for Min as well, I haven't tested.

var query = qf.SubscriberChurnDetail
        .Select(()=>new SubscriberChurnSummaryModel
        {
            CustomerId = SubscriberChurnDetailFields.CustomerId.ToValue<int>(),
            CustomerCode = **SubscriberChurnDetailFields.CustomerCode.SetAggregateFunction(AggregateFunction.Max)
                .ToValue<string>(),**
            SacId = SubscriberChurnDetailFields.SacId.ToValue<int>(),
            Sac = SubscriberChurnDetailFields.Sac.ToValue<string>(),
            State = SubscriberChurnDetailFields.State.ToValue<string>(),
            StartPeriodId = SubscriberChurnDetailFields.StartPeriodId.ToValue<int?>(),
            StartPeriod = SubscriberChurnDetailFields.StartPeriod.ToValue<string>(),
            StartTransactionTypeId = SubscriberChurnDetailFields.StartTransactionTypeId.ToValue<int?>(),
            StartTransactionType = SubscriberChurnDetailFields.StartTransactionType.ToValue<string>(),
            EndPeriodId = SubscriberChurnDetailFields.EndPeriodId.ToValue<int?>(),
            EndPeriod = SubscriberChurnDetailFields.EndPeriod.ToValue<string>(),
            EndTransactionTypeId = SubscriberChurnDetailFields.EndTransactionTypeId.ToValue<int?>(),
            EndTransactionType = SubscriberChurnDetailFields.EndTransactionType.ToValue<string>(), //SubscriberCount = Functions.CountRow().ToValue<int>()
            SubscriberCount = Functions.CountRow().ToValue<int>()

        })
      
        .Where(SubscriberChurnDetailFields.CustomerId==customerIds)
        .Where(SubscriberChurnDetailFields.SacId==sacIds)
        .Where(SubscriberChurnDetailFields.StartPeriodId==periodIds)
        
        .GroupBy(
            SubscriberChurnDetailFields.CustomerId,
            //SubscriberChurnDetailFields.CustomerCode,
            SubscriberChurnDetailFields.SacId,
            SubscriberChurnDetailFields.Sac,
            SubscriberChurnDetailFields.State,
            SubscriberChurnDetailFields.StartPeriodId,
            SubscriberChurnDetailFields.StartPeriod,
            SubscriberChurnDetailFields.StartTransactionTypeId,
            SubscriberChurnDetailFields.StartTransactionType,
            SubscriberChurnDetailFields.EndPeriodId,
            SubscriberChurnDetailFields.EndPeriod,
            SubscriberChurnDetailFields.EndTransactionTypeId,
            SubscriberChurnDetailFields.EndTransactionType
            )

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39766
Joined: 17-Aug-2003
# Posted on: 28-May-2024 08:38:43   

It emits a MAX(field) (or MIN(field)) in the SQL query so if the RDBMS converts that to a meaningful expression it'll work indeed. Tho MAX(string) doesn't immediately tell me what it will do (how is the max of a string calculated for instance?), hence we documented it as for numeric fields only.

We'll add a remark tho that it's not limited to those types.

Frans Bouma | Lead developer LLBLGen Pro