Stuck with this

Posts   
 
    
Dunebuggy
User
Posts: 8
Joined: 18-Sep-2007
# Posted on: 18-Sep-2007 15:23:45   

Hello,

I need an LLBLgen Pro code equivalent for the following SQL statement. Mind that the field 'ReCode' is a VarChar.

SELECT Max(ReCode) FROM Relatie

The sql statement is valid as it works in the SQL query analizer (SQL Server)

I've tried to do it with the following but this doesn't work as it is meant to work only with numeric fields.

Dim filter As IPredicate = (RelatieFields.Recode.SetAggregateFunction(AggregateFunction.Max))

Another way could be

SELECT TOP 1 * FROM relatie ORDER BY ReCode DESC

But i don't know how to do this with LLBLGen Pro. Any ideas on how to do this ?

Thanks in advance,

Daniel

Dunebuggy
User
Posts: 8
Joined: 18-Sep-2007
# Posted on: 18-Sep-2007 15:54:38   

Hello,

After fiddeling around and looking at the different GetMulti versions i came up with the following which works.

Dim col as RelatieCollection
col.GetMulti(Nothing, 1, New SortExpression(New SortClause(RelatieFields.ReCode, SortOperator.Descending)))

after this col(0).ReCode gives me the value i needed.

Still i'm not sure if this is the best way to do this. If anyone has a better solution enlighten me wink

Thanks, Daniël

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 19-Sep-2007 01:07:17   

Hello, try this:

string maxValue = (string) col.GetScalar(RelatieFields.ReCode, AggregateFunction.Max);

Cheers,

Dunebuggy
User
Posts: 8
Joined: 18-Sep-2007
# Posted on: 19-Sep-2007 09:52:07   

Hi Goose,

Thanks for that reply. I needed to change that line a little bit for me to work. As the first agrument of the GetScalar method required an index instead of a field. That and converting the code to VB.net gave the following.

Dim maxValue As String = col.GetScalar(LLBLGen.RelatieFieldIndex.Recode, AggregateFunction.Max)

Cheers,

Daniël