SQL Server分页错误

时间:2010-02-24 04:17:39

标签: sql-server-2005 asp-classic

在我最近的问题中,我在SQL Server中询问了分页方法。阅读有人在那里发表的文章,我想出了以下代码。一切似乎都对我不错,但我收到以下错误:

ORDER BY子句在视图,内联函数,派生表,子查询和公用表表达式中无效,除非还指定了TOP或FOR XML。

 PAGEID = Request.QueryString("PAGEID")

 If PAGEID = "" or PAGEID = 0 Then
  PAGEID = 1
 End If

 RecordsPerPage = 1
 RecordsPageSize = PAGEID * RecordsPerPage

 SQL = "SELECT * FROM ( SELECT I.IMAGESID, I.IMAGESNAME, I.IMAGESSMURL, ROW_NUMBER() OVER (ORDER BY I.IMAGESID) As Row"
 SQL = SQL & " FROM IMAGES I"
 SQL = SQL & " WHERE Row > ("& RecordsPageSize - RecordsPerPage &") AND Row <= ("& RecordsPageSize &") ORDER BY I.IMAGESID DESC"
 Set objImages = objConn.Execute(SQL)

%>
                <div class="row">
                    <label for="Images">Images</label>
<% Do While Not objImages.EOF %>
     <img src="<%=objImages("IMAGESSMURL")%>" alt="<%=objImages("IMAGESNAME")%>" border="0" />
<%
 objImages.MoveNext
 Loop
%>

1 个答案:

答案 0 :(得分:1)

尝试在其中添加另一个“)A”并更改A.imagesid的I.imagesid:

  SQL = SQL & " FROM IMAGES I ) A"
  SQL = SQL & " WHERE Row > ("& RecordsPageSize - RecordsPerPage &") AND Row <= ("& RecordsPageSize &") ORDER BY A.IMAGESID DESC"

错误消息告诉您不能在子查询中使用订单。