存储过程分页
来源:互联网 发布:c语言32个关键字翻译 编辑:程序博客网 时间:2024/05/19 00:14
create database Test
on primary ( name='Test_Data.mdf',
filename='D:/我的资料/sql/备份/Test_Data.mdf'
)
log on
(
name='Test_Data.ldf',
filename='D:/我的资料/sql/备份/Test_Data.ldf'
)
if object_id('tb') is not null drop table tb
create table tb
(
Col int
)
insert into tb select top 50 number from master..spt_values where type='P' and number>0
create proc SplitPage
(
@TableName nvarchar(50),
@PageSize int,--每页显示的数量
@CurrentPage int,--当前第几页
@PageCol nvarchar(50),--排序字段
@OrderNo nvarchar(50)--排序方式(DESC,ASC)
)
as
/*
测试用的
declare @PageCol nvarchar(50)
declare @TableName nvarchar(50)
declare @OrderNo nvarchar(50)
declare @PageSize int
declare @CurrentPage int
set @PageCol='Col'
set @TableName='tb'
set @OrderNo='DESC'
set @PageSize=10
set @CurrentPage=4
*/
declare @sql nvarchar(1000)
set @sql=''
set @sql='
;with hgo as
(
select *,row_number() over(
order by '+@PageCol+' '+@OrderNo+') rank
from '+@TableName+'
)'
set @sql=@sql+'select Col from hgo where rank between '+ltrim((@CurrentPage-1)*@PageSize+1)+' and '+ltrim(@CurrentPage*@PageSize)
--print @sql
exec (@sql)
exec SplitPage 'tb',10,1,'Col','DESC'
Col
-----------
50
49
48
47
46
45
44
43
42
41
(10 行受影响)
exec SplitPage 'tb',10,3,'Col','DESC'
Col
-----------
30
29
28
27
26
25
24
23
22
21
(10 行受影响)
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ws_hgo/archive/2010/05/28/5630493.aspx
- orcale分页 存储过程分页
- 一个分页存储过程
- 一个分页存储过程
- 存储过程分页代码
- 分页存储过程
- 数据库分页存储过程
- 分页存储过程
- 一个分页存储过程
- 分页 SQLServer存储过程
- 分页 SQLServer存储过程
- 存储过程分页
- SqlServer分页存储过程
- 分页的存储过程
- 通用分页存储过程
- sql 存储过程分页
- 分页存储过程
- 分页存储过程2
- 分页的存储过程
- VS2005的并行计算功能支持
- Google的核心竞争技术
- 解决MySQL连接超时Communications link failure due to underlying exception
- 测试工具备查
- WSCRIPT取得当前执行路径
- 存储过程分页
- 系统动力学软件vensim之指数增长
- Keil(Silicon Laboratories IDE)与VC++6.0中LIB库的作用、生成与调用
- 类的sizeofC/C++
- IP Camera 网络摄像机常见设置问题
- 世界500强企业面试最爱九大问题
- pku 1147 Binary codes 【规律】
- IP Camera网络摄像机在线演示安装插件指南
- Winforms:TypeConverter.IsValid中的改动