Talk:How to count records in a Query

static Integer countPrim(container _queryPack) {   Query               countQuery; QueryRun           countQueryRun; QueryBuildFieldList qbfl; Common             common; Integer            counter; int                i;    ;

countQueryRun  = new QueryRun(_queryPack); countQuery     = countQueryRun.query;

for (i = 1; i <= countQuery.dataSourceCount; i++) {       countQuery.dataSourceNo(i).update(false); countQuery.dataSourceNo(i).sortClear; qbfl  = countQuery.dataSourceNo(i).fields; qbfl.dynamic(false); qbfl.clearFieldList; countQuery.dataSourceNo(i).addSelectionField(fieldnum(Common, recId), SelectionField::Count); }

countQueryRun  = new QueryRun(countQuery);

while (countQueryRun.next) {       common  = countQueryRun.get(countQuery.dataSourceNo(1).table); counter = common.RecId; break; }

return counter; } }