窗口函数和NEXT VALUE FOR函数不支持常量作为ORDER BY子句表达式

时间:2013-11-17 19:55:36

标签: sql-server tsql pagination sql-order-by

运行此语句时,我收到错误Windowed functions and NEXT VALUE FOR functions do not support constants as ORDER BY clause expressions.

SELECT * FROM (select ROW_NUMBER() OVER (ORDER BY 'publishdate DESC') as RowNum,
* FROM news WHERE publishdate <=getdate()) as info
WHERE RowNum > 0 AND RowNum <= (100)

我想使用此语句在分页网格视图中检索结果集。

如何运行此语句?

2 个答案:

答案 0 :(得分:4)

SELECT * FROM (select ROW_NUMBER() OVER (ORDER BY publishdate DESC) as RowNum,
* FROM news WHERE publishdate <=getdate()) as info
WHERE RowNum > 0 AND RowNum <= (100)

您不需要' in(ORDER BY发布日期DESC)

答案 1 :(得分:0)

为了将来的参考,我在查询不存在的数据页面时也看到了这个错误(要求的数据行数比数据库中存在的数量多)。