12. Report-Writer Statements : Report Setup Statements : .Sort Statement--Specify Sort Order of Reported Data : Description
 
Share this page                  
Description
The optional .sort statement specifies the ordering that applies to the rows of data to be reported. Report-Writer initially sorts rows on the first column in the list. If several rows have the same value in the first sort column, Report-Writer then sorts them on the second column in the list, and so forth. If there is exactly one sort column, and there are duplicate values for the sort column, all rows with that value appears together, but in an undetermined order relative to each other.
By default, the .sort statement also specifies the columns used as break columns in the report. You can specify break headers and footers for each column, using the .header and .footer statements. A break on one column in the sort list produces a break on all subsequent columns in the sort list.
If you want, you can use the .sort statement to order rows for appearance in the report only, without specifying these columns as break columns. To override the default break specifications in the .sort statement, specify break columns in a .break statement.
An SQL language report specification includes duplicate rows in the data for reports that use the .sort statements. To specify distinct rows, you can specify the ‑6 flag on the report command line.
If you specify variables as the columnname and/or sortorder parameters, Report-Writer evaluates these variables during the loading of the report specification, before retrieving the data.
You can have either a .sort statement or an order by clause in a .query statement but not both in a report specification.
Note:  When using a variable for columnname, specify the same variable identically in corresponding .break, .header, and .footer statements.