To Order Records
You construct business query language (BQL) statements that include ordering of records by using the OrderBy clause in one of the PXSelect classes that has the OrderBy type parameter. (For more information on selecting the PXSelect class, see To Select Records By Using Traditional BQL.)
By default, if the BQL statement does not specify ordering, MYOB Acumatica Framework adds ordering by the data access class (DAC) key fields (in the order of field declaration) in ascending order to the end of the SQL query. You can order the records by the values of one column or multiple columns, or by a condition.
To Order Records by One Column
PXSelectOrderBy<Product, OrderBy<Asc<Product.unitPrice>>>
[list
of columns]
is the list of columns of the Product
table.SELECT [list of columns] FROM Product
ORDER BY Product.UnitPrice
MYOB Acumatica Framework explicitly enumerates the columns of the database table in the SQL query. For details on which columns are enumerated, see Translation of a BQL Command to SQL.
To Order Records by Multiple Columns
To order records by the values in multiple columns, use the OrderBy class and the Asc<Field, NextField> or Desc<Field, NextField> class, as shown in the following sample BQL statement.
PXSelectOrderBy<Product,
OrderBy<Asc<Product.unitPrice, Desc<Product.availQty>>>>
[list of columns]
is the list of columns of the
Product
table.SELECT [list of columns] FROM Product
ORDER BY Product.UnitPrice, Product.AvailQty DESC
MYOB Acumatica Framework explicitly enumerates the columns of the database table in the SQL query. For details on which columns are enumerated, see Translation of a BQL Command to SQL.
To Order Records by a Condition
PXSelectOrderBy<Product,
OrderBy<Asc<
Switch<Case<Where<Product.availQty, Greater<Product.bookedQty>>, True>,
False>>>>
[list of columns]
is the list of columns of the
Product
table.
SELECT [list of columns] FROM Product
ORDER BY
( CASE
WHEN Product.AvailQty > Product.BookedQty THEN 1
ELSE 0
END )
MYOB Acumatica Framework explicitly enumerates the columns of the database table in the SQL query. For details on which columns are enumerated, see Translation of a BQL Command to SQL.