我列出了这个问题
SELECT q.qTitle,q.qDescription,q.qCreatedOn,u.uCode,u.uFullname,qcat.qcatTitle,q.qId,q.qStatus FROM tblQuestion AS q INNER JOIN tblUser AS u ON q.uId = u.uId INNER JOIN tblQuestionCategory AS qcat ON q.qcatId = qcat.qcatId WHERE (q.qStatus = 1) ORDER BY q.qCreatedOn DESC OFFSET @page*10 ROWS FETCH NEXT 10 ROWS ONLY
但是在我的服务器上有一个问题,
Incorrect Syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement.
还有一个问题.如何编写列表页面的存储过程?这是我的代码http://codepaste.net/gq5n6c
解决方法
在注释中发现,错误的原因是因为sql Server 2008不支持它.您可以尝试根据sql Server 2012更改查询.
这样的:
SELECT column1 FROM ( SELECT column1,ROW_NUMBER() OVER (ORDER BY column_id) AS x FROM mytable ) AS tbl WHERE tbl.x BETWEEN 20 AND 30
在你的代码中:
SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY q.qId) AS rownumber FROM tblQuestion AS q INNER JOIN tblUser AS u ON q.uId = u.uId INNER JOIN tblQuestionCategory AS qcat ON q.qcatId = qcat.qcatId ) as somex WHERE somex.rownumber BETWEEN 11 AND 20
问题是因为你没有定义@page.
尝试这个(因为你没有提到什么是@page,我把它当作一些常数,或者你可以声明它,然后设置它的值):
declare @page int set @page = 5 // You may set any value here. SELECT q.qTitle,q.qStatus FROM tblQuestion AS q INNER JOIN tblUser AS u ON q.uId = u.uId INNER JOIN tblQuestionCategory AS qcat ON q.qcatId = qcat.qcatId WHERE (q.qStatus = 1) ORDER BY q.qCreatedOn DESC OFFSET (@page*10) ROWS FETCH NEXT 10 ROWS ONLY