mssql server 2008 的分页查询在“OFFSET"附近抛出错误的语法

我正在研究 jsp 中的分页(我是编写 sql 的新手).

I am Working on pagination in jsp(and i am new to writing sql).

我完成了研究并发现了来自

I done my research and found simple queries from

SQL server 2008 中的分页 和 如何在 SQL Server 2008 中进行分页

SELECT * FROM document  ORDER BY id OFFSET
                    "+iPageNo+"  ROWS FETCH NEXT 10 ROWS ONLY;

在上面的查询中,ipageNo 第一次变为 0(即使我尝试手动输入 1)

in the above query ipageNo is coming 0 for the first time(even i tried by putting 1 manually)

仍然给出错误'OFFSET'附近的语法不正确.

我在这里错过了什么?提前致谢.

What i missed here ? Thanks in advance.

推荐答案

这是我的工作,现在工作正常.

Here is my work around and working fine now.

SELECT * FROM   (SELECT ROW_NUMBER() OVER(ORDER BY id) AS rownumber,*
        FROM document)  as somex  WHERE  rownumber >= (1+1)*10-9
                         AND rownumber <=(1+1)*10

在上面的查询中,我将 (1+1) 替换为 (pageNUMer+1).

In the above query i am replacing (1+1) with (pageNUmber+1).

如果有任何优雅的方式可用,请随时向我建议.

Please feel free to suggest me if any elegant way available.

相关文章