4D v13.4ORDER BY |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v13.4
ORDER BY
ORDER BY
ORDER BY sorts (reorders) the records of the current selection of aTable for the current process. After the sort has been completed, the new first record of the selection becomes the current record. If you omit the aTable parameter, the command applies to the default table, if it has been specified. Otherwise, 4D uses the table of the first field passed as a parameter. If you do not pass a parameter and if no default table has been specified, an error is returned. If you do not specify the aField, the > or < or the * parameters, ORDER BY displays the Order By editor for aTable. The Order By editor is shown here: For more information about using the Order By editor, refer to the 4D Design Reference manual. The user builds the sort, then clicks the Sort button to perform the sort. If the sort is performed without interruption, the OK variable is set to 1. If the user clicks Cancel, the ORDER BY terminates with no sort actually performed, and sets the OK variable to 0 (zero). The following line displays the Order By editor for the [Products] table: ORDER BY([Products]) The following line displays the Order By editor for the default table (if it has been set): ORDER BY If you specify the aField and > or < parameters, the standard Order By editor is not presented and the sort is defined programmatically. You can sort the selection on one level or on several levels. For each sort level, you specify a field in aField and the sorting order in > or <. If you pass the “greater than” symbol (>), the order is ascending. If you pass the “less than” symbol (<), the order is descending. The following line orders the selection of [Products] by name in ascending order: ORDER BY([Products];[Products]Name;>) The following line orders the selection of [Products] by name in descending order: ORDER BY([Products];[Products]Name;<) The following line orders the selection of [Products] by type and price in ascending order for both levels: ORDER BY([Products];[Products]Type;>;[Products]Price;>) The following line orders the selection of [Products] by type and price in descending order for both levels: ORDER BY([Products];[Products]Type;<;[Products]Price;<) The following line orders the selection of [Products] by type in ascending order and by price in descending order: ORDER BY([Products];[Products]Type;>;[Products]Price;<) The following line orders the selection of [Products] by type in descending order and by price in ascending order: ORDER BY([Products];[Products]Type;<;[Products]Price;>) If you omit the sorting order parameter > or <, ascending order is the default. The following line orders the selection of [Products] by name in ascending order: ORDER BY([Products];[Products]Name)
The following line performs an indexed sort if [Products]Name is indexed: ORDER BY([Products];[Products]Name;>) The following line performs a sequential sort, whether or not the fields are indexed: ORDER BY([Products];[Products]Type;>;[Products]Price;>) The following line performs a sequential sort using a related field: ORDER BY([Invoices];[Companies]Name;>) ` Invoices are sorted alphabetically on the Company name field The following example carries out an indexed sort on two levels if a [Contacts]LastName + [Contacts]FirstName composite index has been specified in the database: ORDER BY([Contacts];[Contacts]LastName;>;[Contacts]FirstName;>)
Warning: with this syntax, you can pass only one sort level (field) per ORDER BY call. In an Output form displayed in the Application environment, you allow the users to order a column in ascending order by simply clicking in the column header. Each column header contains a highlight button attached with the following object method: MULTILEVEL(->[CDs]Title) `Title column header button Each button calls the MULTILEVEL project method with a pointer to the corresponding column field. The MULTILEVEL project method is the following: ` MULTILEVEL Project Method
|
PROPERTIES
Product: 4D
INDEX HISTORY
Modified: 4D v11 SQL SEE ALSO |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||