您的位置:首页 > 数据库

分页存储过程--一个简单的SQL存储过程

2008-05-21 21:57 417 查看
运用存储过程可以对数据进行分页,这样提起出的数据也能快速在页面上绑定显示:
create procedure getDate
( @size int,--页面条数大小 @currentPage--当前的页数 )
as
declare @strsql varchar(500)--要执行的SQL语句
declare @newtable varchar(30)--虚拟表名称变量
declare @start int--起始点
declare @end int--结束点
set @newtable='#s'
set @start=(@currentPage-1)*@size+1
set @end=@currentPage*@size
set @strsql='select identity(int ,1,1) as rowindex,test.* into '+@newtable+' from test' set @strsql=@strsql+' select * from '+@newtable+' where rowindex between '+cast(@start as varchar(2))+' and '+cast(@end as varchar(2))+' drop table '+@newtable exec(@strsql)
以上内容参考了/article/4594467.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: