存储过程分页
来源:互联网 发布:界面设计用技术软件 编辑:程序博客网 时间:2024/05/17 21:48
CREATE PROCEDURE GetData
@PageIndex int,
@PageSize int,
@order varchar(24), --排序字段
@method varchar(8), --排序方式
@where varchar(200), --条件语句
@RecordCount int output,
@PageCount int output
AS
declare @methodd varchar(8)
if @method = 'asc'
set @methodd = 'desc'
else if @method = 'desc'
set @methodd = 'asc'
SELECT @RecordCount=count(*) FROM [table] where col1 like +@where
SET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)
DECLARE @SQLSTR NVARCHAR(300)
IF @PageIndex = 0 OR @PageCount <= 1
SET @SQLSTR ='SELECT TOP '+STR( @PageSize )+
' * FROM [table] where col1 like '+@where+' order by '+@order+' '+@method
ELSE IF @PageIndex = @PageCount - 1
SET @SQLSTR ='SELECT TOP '+STR( @RecordCount - @PageSize * @PageIndex )
+' * FROM [table] where col1 like '+@where+' order by '+@order+' '+@method
ELSE
SET @SQLSTR ='SELECT TOP '+STR( @PageSize )+' * FROM ( SELECT TOP '
+STR( @RecordCount - @PageSize * @PageIndex )+' * FROM [table] where col1 like '
+@where+' ORDER BY '+@order+' '+@methodd+' ) nTable order by '+@order+' '+@method
EXEC (@SQLSTR)
GO
------若没条件限制可传where为“'%%'”
@PageIndex int,
@PageSize int,
@order varchar(24), --排序字段
@method varchar(8), --排序方式
@where varchar(200), --条件语句
@RecordCount int output,
@PageCount int output
AS
declare @methodd varchar(8)
if @method = 'asc'
set @methodd = 'desc'
else if @method = 'desc'
set @methodd = 'asc'
SELECT @RecordCount=count(*) FROM [table] where col1 like +@where
SET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)
DECLARE @SQLSTR NVARCHAR(300)
IF @PageIndex = 0 OR @PageCount <= 1
SET @SQLSTR ='SELECT TOP '+STR( @PageSize )+
' * FROM [table] where col1 like '+@where+' order by '+@order+' '+@method
ELSE IF @PageIndex = @PageCount - 1
SET @SQLSTR ='SELECT TOP '+STR( @RecordCount - @PageSize * @PageIndex )
+' * FROM [table] where col1 like '+@where+' order by '+@order+' '+@method
ELSE
SET @SQLSTR ='SELECT TOP '+STR( @PageSize )+' * FROM ( SELECT TOP '
+STR( @RecordCount - @PageSize * @PageIndex )+' * FROM [table] where col1 like '
+@where+' ORDER BY '+@order+' '+@methodd+' ) nTable order by '+@order+' '+@method
EXEC (@SQLSTR)
GO
------若没条件限制可传where为“'%%'”
- orcale分页 存储过程分页
- 一个分页存储过程
- 一个分页存储过程
- 存储过程分页代码
- 分页存储过程
- 数据库分页存储过程
- 分页存储过程
- 一个分页存储过程
- 分页 SQLServer存储过程
- 分页 SQLServer存储过程
- 存储过程分页
- SqlServer分页存储过程
- 分页的存储过程
- 通用分页存储过程
- sql 存储过程分页
- 分页存储过程
- 分页存储过程2
- 分页的存储过程
- 在asp.net中如何实现伪静态页
- 【水晶玻璃鞋 14】带宽、下载速度、网速的区别
- APT持续性渗透攻击的九份报告
- Android Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)
- CSS调试工具推荐
- 存储过程分页
- C#如何保存软件设置项
- OOM的深入解析
- 获取QQ当前状态
- 分享15个在线图片编辑软件
- vs2010 快捷键设置问题 alt+ F8
- Reactor模式,或者叫反应器模式
- Oracle游标执行流程
- 对Vector+Clock算法的理解