By default, a while select statement that returns multiple rows will sort the result ascending by the primary index on the table. You can see this in the first two examples in the previous section.
static void selectRecordsSortedDesc(Args _args)
{
CustTable custtable;
int records;
info("------------------START-------------------");
while select custtable
order by AccountNum desc
{
info("--------------NEW RECORD--------------");
info (strfmt("AccountNum: %1",custtable.AccountNum));
info (strfmt("Name: %1",custtable.name()));
info (strfmt("CustGroup: %1",custtable.CustGroup));
info (strfmt("Currency: %1",custtable.Currency));
records++;
}
info("------------------END-------------------");
info(strfmt("%1 records was selected", records));
}
If you would like to have a statement return the rows in a different order, you have to use the order by parameter in the select statement and specify which fields you would like to sort the result by. If you have an index that corresponds with the sorting, you can use the name of the index to order by as well, but then you will have to use the index statement instead of order by. The following example will return all the records in the CarTablesorted in a descending order of mileage:
static void selectRecordsSortedDesc(Args _args)
{
CustTable custtable;
int records;
info("------------------START-------------------");
while select custtable
order by AccountNum desc
{
info("--------------NEW RECORD--------------");
info (strfmt("AccountNum: %1",custtable.AccountNum));
info (strfmt("Name: %1",custtable.name()));
info (strfmt("CustGroup: %1",custtable.CustGroup));
info (strfmt("Currency: %1",custtable.Currency));
records++;
}
info("------------------END-------------------");
info(strfmt("%1 records was selected", records));
}
No comments:
Post a Comment