自己写的SQL存储过程分页方法
CREATE PROC page
@count int out,
@PageIndex int,
@PageCount int out
AS
SELECT @count = COUNT(id) FROM user1
set @PageCount =floor(@count/10+1)
DECLARE @SQLSTR NVARCHAR(1000)
if @PageIndex=0 or @PageCount<=1
begin
SET @SQLSTR ='select top 10 * from user1 order by id asc'
end
else
begin
if @PageIndex =@PageCount-1
begin
SET @SQLSTR ='select top 10 * from user1 where id not in(select top '+STR(@PageCount*10-10)+' id from user1) order by id asc'
end
else
begin
SET @SQLSTR ='select top 10 * from user1 where id not in(select top '+STR(@PageIndex*10)+' id from user1) order by id asc'
end
end
EXEC (@SQLSTR)
GO
@count int out,
@PageIndex int,
@PageCount int out
AS
SELECT @count = COUNT(id) FROM user1
set @PageCount =floor(@count/10+1)
DECLARE @SQLSTR NVARCHAR(1000)
if @PageIndex=0 or @PageCount<=1
begin
SET @SQLSTR ='select top 10 * from user1 order by id asc'
end
else
begin
if @PageIndex =@PageCount-1
begin
SET @SQLSTR ='select top 10 * from user1 where id not in(select top '+STR(@PageCount*10-10)+' id from user1) order by id asc'
end
else
begin
SET @SQLSTR ='select top 10 * from user1 where id not in(select top '+STR(@PageIndex*10)+' id from user1) order by id asc'
end
end
EXEC (@SQLSTR)
GO