[TOC] [Prev] [Next] [Bottom]



<@SORT>

Syntax

<@SORT ARRAY=arrayVarName [COLS=sortCol [sortType] [sortDir] [, ...]] [SCOPE=scope]>

Description

Sorts the input array by the column(s) specified. This tag does not return anything.

The ARRAY attribute specifies the name of a variable containing an array. The COLS attribute specifies the column(s) to sort by, specified using column numbers or names, with optional sort types (sortType) and directions (sortDir).

Valid sort types are SMART (the default), DICT, ALPHA and NUM. DICT sorts the column alphabetically, irrespective of case. ALPHA is a case-sensitive sort. NUM sorts the column numerically. SMART checks whether values are numeric or alphabetic and sorts using a NUM or DICT type.

Valid sort directions are ASC (the default) and DESC. ASC sorts the column in ascending order, with lower values coming before higher ones. DESC sorts in descending order, with higher values coming before lower ones.

If the COLS attribute is omitted, all columns are sorted left to right using the SMART sort type and the ASC (ascending) sort direction.

The order of the type and direction options are not important, that is, COLS="1 NUM ASC" is equivalent to COLS="1 ASC NUM".

Multiple columns may be specified, separated by commas. Each sort column specification may include a sort type specifier and/or a sort direction specifier. If included, these must follow the sort column, separated by a space.

Multiple sort columns cause the array to be sorted by the first column specified, then, rows with the same value in that column are sorted by the second sort column specified within that previously-created sort order, and so on.

The SCOPE attribute specifies the scope of the variable specified by ARRAY. If not specified, the default scoping rules are used.

Meta tags are permitted in any of the attributes.

Examples

  • If the local variable test contains the following array:
    4 example
    2 is
    7 sorting
    3 an
    5 of
    1 here
    6 array

    <@SORT ARRAY="test" SCOPE="local" COLS="1 NUM"> rewrites the local test variable as the following array:

    1 here
    2 is
    3 an
    4 example
    5 of
    6 array
    7 sorting
  • <@SORT ARRAY="customer" COLS="cust_state, cust_num"> sorts the array stored in customer. The default SMART sort type checks the cust_state column, finds it is alphabetic, and uses sort type DICT; similarly, it checks the cust_num column, finds it is numeric, and uses sort type NUM in the cust_num column for the rows with the same cust_state value.

See Also

<@DISTINCT>
<@FILTER>
<@INTERSECT>
<@UNION>



[TOC] [Prev] [Next] [Bottom]



docs@pervasive.com

Copyright © 1998, Pervasive Software Inc. All rights reserved.