想要一个asp+sql server的存储过程分页代码,可以多表,多字段排序

rdw168 2008-11-06 09:14:29

想要一个asp+sql server的存储过程分页代码,

可以多表,多字段排序(没有多表,单表,多字段排序也行)

说明:本人技术太差,没办法,就只有麻烦大家了,谢谢,搞了好几天了,还没搞过

谢谢大家
...全文
103 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lgq_liang 2009-10-13
  • 打赏
  • 举报
回复
记号
rdw168 2008-11-06
  • 打赏
  • 举报
回复
谢谢一楼的,我明白了
rdw168 2008-11-06
  • 打赏
  • 举报
回复
1楼,有没有例子啊?我不会用啊,在页面里
rdw168 2008-11-06
  • 打赏
  • 举报
回复
谢谢楼上的,好像不能多字段排序啊?
Atai-Lu 2008-11-06
  • 打赏
  • 举报
回复

if not object_id('Cdt_changePage') is null drop procedure Cdt_changePage
go
create procedure [dbo].[Cdt_changePage]
@pagesize int, --每页显示的数据数
@pageindex int, --当前页码
@tbName varchar(20), --表名
@columns varchar(600), --需要查询的字段
@keyIndex varchar(20), --自增字段名(自动编号)
@where varchar(200), --查询条件,不用写where
@order varchar(200) --排序,不用写order by

as
declare @strSQL varchar(3000)
--准备分页
declare @datacount int --总记录数
declare @pagecount int --总页数

if @order=''
begin
set @order=' '+@keyIndex+' desc'
end
--获取总记录数
if not object_id('#cdt_tem') is null drop table #cdt_tem
create table dbo.#cdt_tem(datacount int)
exec('insert #cdt_tem select count(*) as datacount from '+@tbName+' where 1=1 '+@where)
set @datacount=(select top 1 datacount from #cdt_tem)
if not object_id('#cdt_tem') is null drop table #cdt_tem
--计算总页数
if(@datacount%@pagesize)=0
begin
set @pagecount=(@datacount/@pagesize)
end
else
begin
set @pagecount=(@datacount/@pagesize)+1
end

--开始分页
if @pageindex<=1
begin
set @strSQL = 'select top '+str(@pagesize)+' '+str(@datacount)+' as datacount, '+str(@pagecount)+' as pagecount, '+@columns+'
from '+@tbName+' where 1=1 '+@where+' order by '+@order
end
else
begin
set @strSQL = 'select top '+str(@pagesize)+' '+str(@datacount)+' as datacount, '+str(@pagecount)+' as pagecount, '+@columns+'
from '+@tbName+' where '+@keyIndex+'
not in(select top '+str((@pageindex-1)*@pagesize)+' '+@keyIndex+'
from '+@tbName+' where 1=1 '+@where+' order by '+@order+')
'+@where+' order by '+@order
end

exec (@strSQL)
go

exec Cdt_changePage 10,1,'chinaarea','*','Id','','Id asc'

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧