SORTED BY

Sorts the members of the set produced by the main command.

Syntax

SORTED BY «expression [ASCENDING|DESCENDING]»

Parameters

expression

An expression that identifies a field to be used as a sort key. Complex expressions must be enclosed in parentheses.

ASCENDING or DESCENDING

Specifies how the sort on the associated key is to be performed.
ASCENDING (default)
Sorts in "alphabetical order" (A-Z, 0-9).
DESCENDING
Sorts in "reverse alphabetical order" (Z-A, 9-0).

Comments

The sorting clause determines the order in which the selected records are to appear in the set. The fields to be used as sort keys (identified by each expression) must be part of the set produced by the main command.

If you omit the sorting clause, the software determines the order of the records.

Note: Existing result sets can also be sorted after selection - with the SORT command.

Example

list all Employees sorted by Department descending FirstName LastName

The preceding command lists all Employees by department (in descending order) and, within department, by first and last names (in ascending order).

report from Invoices \
 sorted by {$month(InvoiceDate)-5 \
  where $month(InvoiceDate) >= 6, \
  $month(InvoiceDate)+7}
 :
endreport

The preceding program fragment reports invoices in order by fiscal month, assuming that the fiscal year begins in June.

 

Related Topics