order by Clause Restrictions

Restrictions for using the order by clause.

  • The maximum number of columns allowed in an order by clause is 400.

  • You cannot use order by on text, unitext, or image datatype columns.

  • Subqueries and view definitions cannot include an order by clause (or a compute clause or the keyword into). Conversely, you cannot use a subquery in an order by list.

  • You cannot update the result set of a server- or language- type cursor if it contains an order by clause in its select statement. For more information about the restrictions applied to updatable cursors, see the Transact-SQL User’s Guide.

  • If you use compute by, you must also use an order by clause. The expressions listed after compute by must be identical to or a subset of those listed after order by, must be in the same left-to-right order, must start with the same expression, and must not skip any expressions. For example, if the order by clause is:
    order by a, b, c
    the compute by clause can be any (or all) of these:
    compute by a, b, c 
    compute by a, b 
    compute by a

    You can also use the keyword compute can be used without by to generate grand totals, grand counts, and so on. In this case, order by is optional.