Answered ROW_NUMBER() function in SQL 2005

  • Wednesday, February 01, 2006 5:46 PM
     
     

    Can this function accept parameter in the order clause?

    WITH LogEntries AS (
    SELECT ROW_NUMBER() OVER (ORDER BY Date DESC)
    AS Row, Date, Description
    FROM LOG)

    Instead of using "ORDER BY Date DESC", I would like to use "ORDER BY @SORTCOLUMN". But I could not get this to work properly.

     

    Thanks,

     

All Replies

  • Wednesday, February 01, 2006 9:16 PM
     
     Answered
    You could use dynamic sql (execute a string using EXEC or sp_executesql).
  • Thursday, February 02, 2006 4:13 PM
     
     
    Thanks