Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Querybuilder - using count with group by.

384 views
Skip to first unread message

Dave

unread,
May 13, 2010, 3:31:01 PM5/13/10
to
I am trying to get a count of the records I am about to process so that I can
set my upper limit on the progress bar. My query is doing a group by and
when I add a count field to get the count, I get zero back. If I remove the
group by I get the number of records. That number will be too large though.

I can do a while loop and count but that takes more time. I cannot use an
x++ query because my quiery will vary with users selections.

Any ideas?

Luegisdorf

unread,
May 14, 2010, 5:06:01 AM5/14/10
to
Hi Dave

Should work:

Try this sample:

QueryRun qr;
Query query = new Query();
QueryBuildDataSource qbds;

CustTable custTable;
;
qbds = query.addDataSource(tablenum(CustTable));
qbds.addGroupByField(fieldnum(CustTable, CountryRegionId));
qbds.addSelectionField(fieldnum(CustTable, RecId), SelectionField::Count);

qr = new QueryRun(query);

while (qr.next())
{
custTable = qr.get(tablenum(CustTable));
info(strfmt("in Country %1, there are %2 customers",
custTable.CountryRegionId, custTable.RecId));
}


For each country you get the count.

Regards
Patrick

0 new messages