Sort DataTable
Use this command to sort data in a DataTable by a particular column. Sorting does not actually alter the order of items in the DataTable object; it creates a temporary sort index that you can use to improve performance when using the Fetch command with Open Cursor.
If you specify multiple columns, they are sorted in the order in which they appear in the SORT DATATABLE statement.
Note: The Insert DataTableRow and Delete DataTableRows commands inherently use the Sort feature. If you sort prior to using these commands, your sort will be overwritten.
Syntax:
SORT DATATABLE DataTable "ColumnName [ASC|DESC], ..."
where:
- DataTable is the name of the DataTable object to sort.
- ColumnName is the column to sort by. If the column name contains spaces, you must enclose it in square brackets. For example, [Employee Type].
- ASC sorts the column by ascending alphabetic or numeric order.
- DESC sorts the column by descending alphabetic or numeric order.
Syntax example:
SORT DATATABLE EmpSalaries "[Office Location] ASC, [Employee Type] DESC"
Syntax example:
SORT DATATABLE TopAccounts "State ASC, [Sales Amount] DESC"
See also