码迷,mamicode.com
首页 > 其他好文 > 详细

分页及万能分页

时间:2015-04-28 09:25:39      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

create database 万能分页
use 万能分页
 create table student      --创建表格
 (
   code int primary key identity(1,1) not null,  --列
   name varchar(50)not null,    --列
   sex varchar(50)not null,    --列
   age int not null,          --列
   [weight] int not null,         --列
   hight int not null,       --列
   idno int not null,      --列
   iddress varchar(50) not null,    --列
 )
 go      --连接符
 insert into student values(‘张三‘,‘男‘,18,78,180,371521,‘淄博‘)  --添加表中信息
 insert into student values(‘李四‘,‘女‘,21,55,170,371522,‘济南‘)
 insert into student values(‘王五‘,‘男‘,17,70,178,371523,‘周村‘)
 insert into student values(‘赵六‘,‘女‘,22,50,167,371524,‘北京‘)
 insert into student values(‘田七‘,‘男‘,23,81,175,371525,‘南京‘)
 insert into student values(‘赵丹‘,‘男‘,27,81,175,371525,‘南京‘)
 insert into student values(‘张可‘,‘男‘,18,78,180,371521,‘淄博‘)  
 insert into student values(‘李文‘,‘女‘,21,55,170,371522,‘济南‘)
 insert into student values(‘王付‘,‘男‘,17,70,178,371523,‘周村‘)
 insert into student values(‘赵和‘,‘女‘,22,50,167,371524,‘北京‘)
 insert into student values(‘田收‘,‘男‘,23,81,175,371525,‘南京‘)
 insert into student values(‘赵进‘,‘男‘,27,81,175,371525,‘南京‘)
 select*from student
 --后面的not in是屏蔽掉当前页的前面页的内容  前面top是取屏蔽之后的数据的一页显示条数   必须要用主键的列  只能查连续的数据  
 select top 4 *from student where  code not in(select top 6 code from student )    
 --分页的存储过程
 create proc fenye
 
 @nowye int, --当前页
 @numbers int  --显示行数
 as
  select top (@numbers) *from student where  code not in(select top ((@nowye-1)*@numbers ) code from student )    --显示第三页的行数 首先去掉前两页的行数 所以才(当前页-1)*行数
 go
 exec  fenye 3,2
 
 create proc wannengfenye            --组合主键不能用
@nowye int,--当前页
@numbers int, --一显示行数
@tablename varchar(50),--表名
@zhujian varchar(50)  --只能用主键列  因为主键列没有重复的        
as                          
exec (‘select top (‘+@numbers+‘) *from ‘+@tablename+‘  where ‘+@zhujian+‘ not in        
 (select top ((‘+@nowye+‘-1)*‘+@numbers+‘) ‘+@zhujian+‘ from ‘+@tablename+‘ )‘)  --  直接写表名,主键不能执行 只能写成字符串形式  让exec加括号去执行里面的字符串
go
exec wannengfenye 3,3,‘student‘,‘code‘

 

分页及万能分页

标签:

原文地址:http://www.cnblogs.com/Mr-xue/p/4462078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!