一个简单可以直接调用的sqlserver分页存储代码
SQL分页存储过程代码:CREATE procedure p_splitpage
@sql nvarchar(4000), --要执行的sql语句
@page int=1, --要显示的页码
@pageSize int, --每页的大小
@pageCount int=0 out, --总页数
@recordCount int=0 out --总记录数
as
set nocount on
declare @p1 int
exec sp_cursoropen @p1 output,@sql,@scrollopt=1,@ccopt=1,@rowcount=@pagecount output
set @recordCount = @pageCount
select @pagecount=ceiling(1.0*@pagecount/@pagesize)
,@page=(@page-1)*@pagesize+1
exec sp_cursorfetch @p1,16,@page,@pagesize
exec sp_cursorclose @p1
GO
调用代码:<%
dim text,checkpage
text="0123456789"
for i=1 to len(request("page"))
checkpage=instr(1,text,mid(request("page"),i,1))
if checkpage=0 then
exit for
end if
next
If checkpage<>0 then
If NOT IsEmpty(request("page")) Then
m_page=Cint(request("page"))
If m_page < 1 Then m_page = 1
Else
m_page= 1
End If
Else
m_page=1
End if
m_pagesize=40'每页的条数
set cmd = server.CreateObject("adodb.command")
cmd.ActiveConnection = conn
cmd.CommandType = 4
cmd.CommandText = "p_SplitPage"
cmd.Parameters.Append cmd.CreateParameter("@sql",8,1, 4000, sql)
cmd.Parameters.Append cmd.CreateParameter("@page",4,1, 4, m_page)
cmd.Parameters.Append cmd.CreateParameter("@pageSize",4,1, 4, m_pageSize)
cmd.Parameters.Append cmd.CreateParameter("@pageCount",4,2, 4, m_pageCount)
cmd.Parameters.Append cmd.CreateParameter("@recordCount",4,2, 4, m_recordCount)
set rs = cmd.Execute
set rs = rs.NextRecordSet
m_pageCount = cmd.Parameters("@pageCount").value
m_recordCount = cmd.Parameters("@recordCount").value
if m_pageCount = 0 then m_pageCount = 1
if m_page>m_pageCount then
response.Redirect("zzzyk.asp?page="&m_pageCount&"")
end if
set rs = cmd.Execute
%>