create database DB_8_6
use DB_8_6
create table Address
(
Aid int primary key identity,
Aname varchar(40)
)
insert into Address values('河南');
insert into Address values('上海');
insert into Address values('北京');
select * from Address
create table Student
(
Sid int primary key identity,
Sname varchar(40),
Sex varchar(40),
Sage int,
Aid int
)
insert into Student values('张三','男','19','1');
insert into Student values('李四','男','20','2');
insert into Student values('王红','女','22','3');
select * from Student s join Address a on s.Aid=a.Aid
create proc Proc_Page
@PageIndex int,
@PageSize int,
@Count int output
as
begin
begin tran
commit tran
select @Count =COUNT(*) from Student
declare @PageCount int
if(@PageIndex < 1)
begin
set @PageIndex = 1
end
if(@PageCount % @PageSize = 0)
begin
select @PageCount =@PageCount / @PageSize
end
if(@PageCount % @PageSize = 1)
begin
select @PageCount =@PageCount /@PageSize+1
end
if(@PageIndex >@PageCount)
begin
set @PageIndex =@PageCount
end
select * from
(select ROW_NUMBER() over(order by Sid) as RowT,* from Student)
as Wpage join Address a on a.Aid=Wpage.Sid where RowT between
(@PageIndex -1) * @PageSize and @PageSize
end
drop proc Proc_Page
declare @a int
declare @b int
exec Proc_Page 1,2,@a out
select @a 总页数