where startdatetime <> enddatetime
group by ConnectionId, ContractNum
having count(ConnectionId) > 1
order by min(ENDDATETIME) desc
static void Job10(Args _args)
{
Query query = new Query();
QueryRun queryRun;
QueryBuildDataSource qbdsMcsCmBilAgreement;
McsCmBilAgreement agreement, agreement2;
qbdsMcsCmBilAgreement = query.addDataSource(tableNum(McsCmBilAgreement));
qbdsMcsCmBilAgreement.addSortField(fieldNum(McsCmBilAgreement,StartDateTime),SortOrder::Ascending);
qbdsMcsCmBilAgreement.addGroupByField(fieldNum(McsCmBilAgreement, connectionid));
qbdsMcsCmBilAgreement.addGroupByField(fieldNum(McsCmBilAgreement, contractnum));
query.addHavingFilter(qbdsMcsCmBilAgreement, fieldStr(McsCmBilAgreement, connectionid), AggregateFunction::Count).value("> 1");
info(query.toString());
queryRun = new QueryRun(query);
while(queryRun.next())
{
agreement = queryRun.get(tableNum(McsCmBilAgreement));
info(strFmt("%1 %2 %3 %4", agreement.ConnectionId, agreement.ContractNum, agreement.StartDateTime, agreement.EndDateTime));
}
}