Example: Sort

This query finds all open incidents for which your department is the service owner of the affected service, and sorts by service name in ascending order and incident number in descending order:

Note If possible, use the order by clause in the query instead of setsort(), because the order by clause sort fields before the select operation. setsort() requires another SQL operation to sort. setOrderBy is not supported in cross table query.

var file = new SCFile("probsummary");
var sql = "select p.*, d.logical.name as lname from probsummary p LEFT OUTER JOIN device d ON (p.affected.item=d.logical.name) where d.owner=$lo.dept and p.flag=true";
sql += " order by d.logical.name asc, p.number desc"
var success = file.doSelect(sql);
while (success == RC_SUCCESS) 
{
         findNextRecord = file.getNext();
}