Home > database >  Sorting DESC results in "Invalid column name" error
Sorting DESC results in "Invalid column name" error

Time:03-17

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.

CodePudding user response:

Try this:

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

CodePudding user response:

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

  • Related