Hi Franz,
I'm having a bit of trouble trying to work out how to do a particular SQL statement in LLBL.
This is the SQL that i would like to do in LLBL:
SELECT XCoord, YCoord, MAX(ZCoord) as ZCoord,
(SELECT SMS_DestinationUID FROM SMS_Block
WHERE XCoord = B.XCoord AND YCoord = B.YCoord AND ZCoord = MAX(B.ZCoord)
AND SMS_PadUID = @PadUID
AND BlockInTime <= @StartDate
AND (BlockOutTime IS NULL OR BlockOutTime >= @StartDate)) as SMS_DestinationUID
FROM SMS_Block B
WHERE B.SMS_PadUID = @PadUID
AND B.BlockInTime <= @StartDate
AND (B.BlockOutTime IS NULL OR BlockOutTime >= @StartDate)
AND B.XCoord >= @minX AND B.XCoord <= @maxX
AND B.YCoord >= @minY AND B.YCoord <= @maxY
AND B.ZCoord >= @minZ AND B.ZCoord <= @maxZ
GROUP BY XCoord, YCoord
In another section i'm returning the max of Z grouped by X and Y by using the following code:
IDataAccessAdapter da = DataManager.CreateAdapter();
HelperClasses.EntityCollection blockCollection = new EntityCollection();
blockCollection.EntityFactoryToUse = new SMS_BlockEntityFactory();
//Get the standard block predicate
IRelationPredicateBucket relationBucket = GetBlockPredicate(dt);
//Allow you to specify a maximum height
relationBucket.PredicateExpression.Add(PredicateFactory.CompareValue(SMS_BlockFieldIndex.ZCoord, ComparisonOperator.LessEqual, this.GetZBlockFromCoord(zMax)));
//Set up fields to return X,Y and Z max
ResultsetFields fields = new ResultsetFields(3);
fields.DefineField(SMS_BlockFieldIndex.XCoord, 0, "XCoord");
fields.DefineField(SMS_BlockFieldIndex.YCoord, 1, "YCoord");
fields.DefineField(SMS_BlockFieldIndex.ZCoord, 2, "ZCoord");
fields[2].AggregateFunctionToApply = AggregateFunction.Max;
//Group by X,Y
IGroupByCollection groupByClause = new GroupByCollection();
groupByClause.Add(fields[0]);
groupByClause.Add(fields[1]);
da.FetchTypedList(fields, internalSurfaceTable, relationBucket, 0, null, true, groupByClause);
Is there anyway to do this without including the SMS_Destination in the Group By statement?
Table Definition:
SMS_BlockUID uniqueIdentifier primary key
XCoord float
YCoord float
ZCoord float
SMS_DestinationUID uniqueIdentifier
Thanks,
Daniel