-1

I have a table MOVIE with a column Desc which stands for description.

I tried to sort by this column:

SELECT 
    * ,
    ROW_NUMBER() OVER (ORDER BY [Desc] ASC) AS RowData
FROM 
    (SELECT
         UID,
         Title,
         [Desc] AS '[Desc]'
     FROM 
         MOVIE) AS RowTable

I get this error

Msg 207, Level 16, State 1, Line 3
Invalid column name 'Desc'

Anyone able to help?

Thank you.

Dale K
  • 25,246
  • 15
  • 42
  • 71
henryloke
  • 67
  • 5
  • change '[Desc]' to 'Desc' or [Desc] – RF1991 Mar 17 '22 at 05:06
  • or in your first select use [[Desc]] – RF1991 Mar 17 '22 at 05:49
  • 1
    And this is why we avoid using the names of keywords as names of our columns. – Damien_The_Unbeliever Mar 17 '22 at 08:59
  • `[Desc] AS '[Desc]'` Here is your problem. Firstly, don't use keywords as names EVER - avoid the complications you create for yourself! Here you changed the column name to include the brackets. Why? There is NO reason to use an alias here at all as you don't do anything useful with it. Just remove it and your query will work. But better yet is to not use keywords as names. – SMor Mar 17 '22 at 12:02

2 Answers2

0

Try this:

SELECT 
    * ,
    ROW_NUMBER() OVER(ORDER BY [Desc] ASC) AS RowData
FROM 
(
    SELECT
        UID,
        Title,
        [Desc] AS [Desc]
    FROM 
        MOVIE
) As RowTable
Nayanish Damania
  • 542
  • 5
  • 13
0

My suggestion is change The column name of Desc. either write description or another name.

beacuse IN SQL

The DESC command is used to sort the data returned in descending order

Dharman
  • 30,962
  • 25
  • 85
  • 135
Developer
  • 89
  • 1
  • 14