Use an ORDER BY  clause to sort records in a SQL statement.
 
For example:
  • A hard-coded SQL statement:

    SELECT * FROM NameAddress ORDER BY Last

  • A hard-coded SQL statement to sort by two fields named Last and First:

    SELECT * FROM NameAddress ORDER BY Last, First

  • An RPG statement to create a soft-coded SQL statement with an ORDER BY statement at the end of the SQL string:

    Note: To test this code, copy it into the SQTEST23R program in RJSRPGSQL.

    C                   Eval      SQLStmt = 'SELECT * FROM NameAddress ' + 
    C                             'WHERE Last LIKE ' + QUOT + '%' +        
    C                             %trimr(ILAST) + '%' + QUOT + ' AND ' +   
    C                             'First LIKE ' + QUOT + '%' +             
    C                             %trimr(IFIRST) + '%' + QUOT +            
    C                             ' ORDER BY Last '

Still have questions? We can help. Submit a case to technical support

Last Modified On:
You don't have the appropriate permissions.
No, open a new Support Case