订单不起作用

时间:2010-12-31 08:26:10

标签: sql-server

With Results as
(
    SELECT Top(100) percent ROW_NUMBER() over (Order by (select 1)) as RowNumber, 
    Ad.Date, Title
     FROM Ad inner join Job on Ad.Id = Job.AdId
     Order by
     case When @sortCol='Date' and @sortDir='ASC' Then Date End ASC,
     case When @sortCol='Date' and @sortDir='DESC' Then Date End DESC
)
Select * from Results
Where RowNumber BETWEEN @FirstRow AND @LastRow
 END

无论在@sortDir和@sortCol中传递什么,它都不起作用。我做错了什么?

1 个答案:

答案 0 :(得分:3)

order by子句移动到Row_Number参数列表可以解决您的问题。

<{1}}条款中的

Order by是不允许的。