Difference between revisions of "SORT"

From Recital Documentation Wiki
Jump to: navigation, search
Line 1: Line 1:
=SORT=
 
 
 
 
==Class==
 
==Class==
 
Fields and Records
 
Fields and Records
Line 21: Line 18:
  
 
==See Also==
 
==See Also==
[[INDEX]], [[DESCEND()]],[[ SET INDEX]]
+
[[DESCEND()]], [[INDEX]], [[SET INDEX]]
  
  
Line 43: Line 40:
 
use patrons
 
use patrons
 
sort to temp on date/a, event/ac, name/ac;
 
sort to temp on date/a, event/ac, name/ac;
for year(date)=1999
+
  for year(date)=1999
 
</code>
 
</code>
  
Line 51: Line 48:
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Commands]]
 
[[Category:Commands]]
 +
[[Category:Table Basics]]
 +
[[Category:Table Basics Commands]]

Revision as of 14:42, 2 June 2009

Class

Fields and Records


Purpose

Sort a table to another in a specific order


Syntax

SORT [<scope>] TO <.dbf filename> | (<expC>)

ON <field> [/A] [/D] [/C]

[FOR <condition>]

[WHILE <condition>]


See Also

DESCEND(), INDEX, SET INDEX


Description

The SORT command copies records from the currently selected table to another table in the specified sorted order. The file name can be substituted with a <expC>, enclosed in round brackets, which returns a valid filename. If no file extension is specified, '.dbf' is used. If no <scope> is specified, a scope of ALL is used, unless the WHILE clause is specified, in which case the <scope> will default to REST. When you want to sort a table on multiple fields, then you should specify the most important field first.

/A /D /C

The /A, /D, and /C options can be specified for each sort field. The /A option sorts on the specified field in ascending order. The /D option sorts in descending order. The /C option can be used in conjunction with /A or /D to provide case insensitive sorting for character fields. For example, /AC causes the Recital/4GL to treat all characters in the sort field as upper case. If no sort order is specified on a field, then /A is assumed.

FOR <condition>

If the FOR <condition> is specified, then only those records which satisfy the specified <condition> are processed.

WHILE <condition>

The WHILE <condition> is often used in conjunction with the SEEK command, and the REST <scope>, to restrict the range of records processed, and therefore reduce the time needed to sort the table.

If the currently selected table is indexed, then SORT processes the records in order of the master index. You cannot sort on logical fields. You cannot sort a table on expressions using the SORT command, this can be achieved using the INDEX command. The INDEX command is a much faster way of organizing a table. The DESCEND() function can be used with the INDEX command to create indexes in descending order.


Example

use patrons
sort to temp on date/a, event/ac, name/ac;
  for year(date)=1999


Products

Recital Database Server, Recital Mirage Server, Recital Terminal Developer