Return an order-by list to a client.
CS_RETCODE srv_orderby(spp, numcols, collistp)
SRV_PROC *spp; CS_INT numcols; CS_INT *collistp;
A pointer to an internal thread control structure.
The number of columns in the order-by list. Because the columns are passed as an array of CS_INTs, numcols is really the number of elements in the collistp array.
A pointer to the array of column numbers. The size of this array is numcols.
Returns  | 
To indicate  | 
|---|---|
CS_SUCCEED  | 
The routine completed successfully.  | 
CS_FAIL  | 
The routine failed.  | 
#include <ospublic.h>
/*
** Local Prototype
*/
CS_RETCODE ex_srv_orderby PROTOTYPE((
SRV_PROC *spp
));
/*
** EX_SRV_ORDERBY
**
** Example routine using srv_orderby to define and return to a
** client application the order-by list for a simple SQL
** command.
** This example uses the SQL command:
**
** “select a,b,c,d from my_tab
** order by c,a”
**
** Arguments:
** spp A pointer to the internal thread control structure.
**
** Returns:
** CS_SUCCEED Order-by list was successfully defined.
** CS_FAIL An error was detected..
*/
CS_RETCODE ex_srv_orderby(spp)
SRV_PROC *spp;
{
    /* There are two columns specified in the order-by clause. */
    CS_INT        collist[2];
    CS_INT        numcols;
    /* Initialization. */
    numcols = 2;
    /*
    ** Initialize the collist array in the order the
     ** columns occur in the order-by clause.
    **
    ** “c” is the 1st column specified in the order-by,
     ** and is the 3rd column specified in the select-list.
    */
    collist[0] = (CS_INT)3;
    /*
    ** “a” is the 2nd column specified in the order-by,
     ** and is the 1st column specified in the select-list.
    */
    collist[1] = (CS_INT)1;
    /*
    ** Define the order-by list.
    */
    if (srv_orderby(spp, numcols, collist) != CS_SUCCEED)
    {
        return(CS_FAIL);
    }
    return(CS_SUCCEED);
}
srv_orderby is necessary only if you want to mimic Adaptive Server Enterprise’s feature of returning order-by information.
srv_orderby allows an Open Server application to return information about sort order to a client. In the SQL command:
select a, b, c, d
order by c, a
The sort order is column c followed by column a. The application returns this information to the client by listing column 3 followed by column 1 in the column number array.
The first column in a select list is column 1.
srv_orderby must be called after a call to srv_descfmt and before a call to srv_bind.