The ORDER BY position number %ld is out of range of the number of items in the select list.

Error Message:
Server: Msg 108, Level 15, State 1, Line n
The ORDER BY position number x is out of range of the number of items in the select list.

Severity level:
15.

Description:
SQL Server allows to reference a column in the ORDER BY clause by its ordinal position in the final resultset. This message appears when you specify a position number in the ORDER BY clause that doesn’t have a corresponding column in the SELECT list. For illustration purposes see the examples below.

Consequences:
The SQL statement cannot be parsed and further execution is stopped.

Resolution:
Error of the severity level 15 are generated by the user and can be fixed by the SQL Server user.

Versions:
All versions of SQL Server.

Example(s):
SELECT OrderID
  FROM Northwind..Orders
 ORDER BY 0

SELECT c1
  FROM
   (SELECT 1 UNION ALL
    SELECT 2 UNION ALL
    SELECT 3) AS t (c1)
 ORDER BY 2

Remarks:
The first statement is invalid because there is no column position 0 in the SELECT list. Likewise the second query is invalid, because there is no position number 2 in the SELECT list. For both queries an ORDER BY 1 would make the statements valid and executable.




Related Articles :

  • No Related Articles Found

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |