public override object Aggregate(int[] records, AggregateType kind)
{
bool hasData = false;
try
{
switch (kind)
{
case AggregateType.Min:
SqlDateTime min = SqlDateTime.MaxValue;
for (int i = 0; i < records.Length; i++)
{
int record = records[i];
if (IsNull(record))
continue;
if ((SqlDateTime.LessThan(_values[record], min)).IsTrue)
min = _values[record];
hasData = true;
}
if (hasData)
{
return min;
}
return _nullValue;
case AggregateType.Max:
SqlDateTime max = SqlDateTime.MinValue;
for (int i = 0; i < records.Length; i++)
{
int record = records[i];
if (IsNull(record))
continue;
if ((SqlDateTime.GreaterThan(_values[record], max)).IsTrue)
max = _values[record];
hasData = true;
}
if (hasData)
{
return max;
}
return _nullValue;
case AggregateType.First:
if (records.Length > 0)
{
return _values[records[0]];
}
return null;// no data => null
case AggregateType.Count:
int count = 0;
for (int i = 0; i < records.Length; i++)
{
if (!IsNull(records[i]))
count++;
}
return count;
}
}
catch (OverflowException)
{
throw ExprException.Overflow(typeof(SqlDateTime));
}
throw ExceptionBuilder.AggregateException(kind, _dataType);
}