The ORDER BY position number is out of range of the number of items in the select list.
This error occurs when specifying the column index or position number in an ORDER BY clause in your SELECT statement and the column index or position number is either 0 or higher than the number of columns specified in the SELECT clause.
This error usually happens when you are using the index in the ORDER BY clause instead of the column name and you have either used 0 or the position that is higher than the number of columns specified in the SELECT clause.
Use AdventureWorks2017
Go
Select FirstName,MiddleName,LastName
from Person.Person
Order By 4
OutPut:
The ORDER BY position number 4 is out of range of the number of items in the select list.
Use AdventureWorks2017
Go
Select FirstName,MiddleName,LastName
from Person.Person
Order By FirstName
One of the advantages of specifying the column name instead of the index is that even you add new columns in to the SELECT clause, you will have the desired result with-out any errors. Using index for sorting will result in undesired results when you add new columns in to your SELECT clause.