分页及万能分页

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  --显示行数asselect top (@numbers) *from student where  code not in(select top ((@nowye-1)*@numbers ) code from student )    --显示第三页的行数 首先去掉前两页的行数 所以才(当前页-1)*行数goexec  fenye 3,2create 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加括号去执行把'+@tablename+'转换为'student'的字符串
go
exec wannengfenye 3,3,'student','code'

 

转载于:https://www.cnblogs.com/Mr-xue/p/4462078.html


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部