Dynamic list with conditional field.

Posts   
 
    
URSC-EST
User
Posts: 8
Joined: 26-Sep-2007
# Posted on: 18-Feb-2009 20:11:17   

I'm using version 2.5 adapter.

I'm trying to figure out how to do the following.

Retrieve records from a transaction table and a couple of other linked tables. All these transactions have a start and end date. I would like to add a column containing a boolean telling me if the start date of a record is equal to the max start date of all records. I would like to avoid making a view for this but I wouldnt mind a typed list.

Would it be possible to have one of the resultset fields give a result similar to this? If(startDate==maxStartDate) return true else return false

Here are the fields.

ResultsetFields fields = new ResultsetFields(6);
            fields.DefineField(CadetCorpsGroupAssignmentFields.Id, 0, "KeyId");
            fields.DefineField(CadetCorpsFields.Name, 1, "CadetCorpsName");
            fields.DefineField(CadetCorpsGroupFields.Name,2);
            fields.DefineField(CadetCorpsGroupAssignmentFields.StartDate,3);
            fields.DefineField(CadetCorpsGroupAssignmentFields.EndDate, 4);
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Feb-2009 09:47:06   

First step os to think about it in terms of SQL. Post the SQL statement that you want to execute, and then we shall try to help you implement it in LLBLGen terms.

URSC-EST
User
Posts: 8
Joined: 26-Sep-2007
# Posted on: 19-Feb-2009 21:28:33   

Well I think it would be something like this

Select StartDate,EndDate,Id,CadetId, cadetCorpsGroupId, 'IsEditable' = CASE (select max(startDate) from cadetcorpsstructure.CadetCorpsGroupAssignment) WHEN StartDate THEN 1 ELSE 0 END from cadetcorpsstructure.CadetCorpsGroupAssignment

Fist though...I dont know if that would be a good way to do it. Would the select max only be done once or would it be done for every row ?

Thx.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 19-Feb-2009 21:50:38   

You can check if it is only run once by looking at the query execution plan in SQL server - it should be.

Have a look at the documentation about using a DBFunction call - there is even an example about using a CASE statment in there simple_smile

Matt

URSC-EST
User
Posts: 8
Joined: 26-Sep-2007
# Posted on: 20-Feb-2009 18:20:51   

Thx that really helped. Plus I can pass a IScalarQueryExpression to the function.

I guess now I can do pretty much everything I wanted.