Results Autoordering
The AUTOORDER clause allows you to include automatic field generation for ordering query results.
Autoorder functions according to the following principles:
- If the ORDER BY clause is indicated in the query, then each reference to a table located in this clause will be replaced by fields used to sort the table by default (for catalogs it is a code or description, for documents it is a document date). If the field for ordering refers to a hierarchical catalog, then hierarchical sorting for this catalog will take place.
- If the ORDER BY clause is not in the query, but the TOTALS clause is, then the query result will be ordered by fields present in the TOTALS clause after the keyword BY, in the same sequence; if totals are calculated by reference fields, the result is ordered by sorting fields of default tables that contained the references.
- If ORDER BY and TOTALS are not in the query, but the GROUP BY clause is, then the query result will be ordered by fields present in the clause, in the same sequence; if grouping is based on reference fields, then the result is ordered by sorting fields of default tables that contained references.
- In the case if neither ORDER BY, TOTALS or GROUP BY are in the query, then the result will be ordered by default sorting fields for tables used to select data, in the order those fields appear in the query.
If the query contains the TOTALS clause, totals are ordered separately by levels.