Sorting Hierarchies

Top  Previous  Next


The Edit Sorting Hierarchy dialog is used to enter one or more expressions to determine a sorting order of records, for instance in Queries.  Each expression is shown in a grid, with the typical functions to Add, Edit, Copy, Delete and Move the expressions.  


Since the expressions are used in the order shown here, the order of expressions in the list determines the sorting hierarchy.  In other words, the first expression is the most important and is compared first, and if that still results in equal values then it will compare using the next expression, etc.


There will be appropriate context information for each expression, since the expressions are used to compare specific records or other specific information to be sorted.  The exact nature of the context will depend on where the sorting hierarchy is used, but for instance if it's the default sorting hierarchy in a Query with a base table of Customers, then the context function ThisCust will be available (or the generic version, ThisRecord, can also be used).  


When sorting is done, it actually executes each expression twice (once with the context of each record to be compared), and then compares the results. Therefore the expressions can result in any type of value -- text, numeric, date, etc. -- the program will know how to compare them.  You don't have to actually do the comparison in the expression, just make the expression be the values to be compared.  


Lets say we have a Query with the Reservations base table.  To have a default sorting of customers by last name, and then secondarily sort by first name if the last names are the same, and a third level of sorting by the number of nights in the reservation (if the same customer), the sorting expressions would be:


 Upper( Cust:Cust_Last_Name )

 Upper( Cust:Cust_First_Names )

 Resv Nights( ThisResv() )


Note that we used the Upper() function on the names so that it doesn't matter whether the names are upper or lower case (or mixed-case).  Also note that the shorthand field descriptor is used (e.g. Cust:Cust_Last_Name) instead of a function like FieldText(ThisCust(), "Cust_Last_Name").  The shorthand should generally be used everywhere possible, since it does more work during parsing and less during execution




Additional Topics:


Queries Overview

Queries Setup

Editing List Queries

Editing Query Columns

Filter Conditions

Save & Test Queries

Editing Cross-Table Queries

Cross-Table Axis/Groupings

Cross-Table Custom Groupings




Color Schemes


Advanced Customizations Overview & other topics




Page URL

Campground Master Home