Share via

Order By Index doesnt work any more afer sql 2019 update.

Rod Martin 136 Reputation points
2021-09-13T13:09:09.23+00:00

Very simple query. I just need to sort by Index. Used to do this all the time. Whats the deal?

SELECT TOP (1000) [Index]
      ,[Product]
      ,[Company]
      ,[WONum]
      ,[MatlNum]
      ,[SealMatlNo]
      ,[ValveOptions]
      ,[Misc#]
      ,[5]
  FROM [Powerapps].[dbo].[SN_Test_DF_Idx_Full2]
  order by Index asc

Msg 1018, Level 15, State 1, Line 12
Incorrect syntax near 'Index'. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. See SQL Server Books Online for proper syntax.

Other columns work fine. This has neven been an issue before.

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Olaf Helper 47,616 Reputation points
    2021-09-13T13:13:17.313+00:00

    INDEX is a reserved key word, you have to set it in brackets [ ] =>

     SELECT TOP (1000) [Index]  
           ,[Product]  
           ,[Company]  
           ,[WONum]  
           ,[MatlNum]  
           ,[SealMatlNo]  
           ,[ValveOptions]  
           ,[Misc#]  
           ,[5]  
       FROM [Powerapps].[dbo].[SN_Test_DF_Idx_Full2]  
       order by [Index] asc  
    

    See Reserved Keywords (Transact-SQL)

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Rod Martin 136 Reputation points
    2021-09-13T13:17:21.237+00:00

    @Olaf Helper ,

    Yep! That did it.

    So, is it bad form to name this column "Index"???

    Thx.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.