Table :
Store Procedure:
In this store procedure I used cursor
CREATE PROCEDURE Pageing
@pagenumber int, --5
@pagesize int --5
AS
BEGIN
declare @srec int --starting record 21
declare @erec int --ending record 21
declare @sbid int --starting book id
declare @ebid int --ending record
declare @rc int -- record count
--set @srec=@pagenumber * @pagesize-@pagesize+1
--use any one of the query both are correct above or below
set @srec=(@pagenumber-1)*@pagesize+1
declare c_book scroll cursor for
select bookid from tbbook order by bookid
open c_book
fetch absolute @srec from c_book into @sbid
--Absolute set the pointer everytime at begining
--Relative can be used but that does not put the pointer on begining everytime
select @rc=COUNT(*) from tbbook where bookid>@sbid
if @rc<@pagesize
set @erec=@srec+@rc
else set @erec=@pagenumber*@pagesize
fetch absolute @erec from c_book into @ebid
close c_book
deallocate c_book
select COUNT(*) from tbbook
select * from tbbook where bookid>=@sbid and bookid<=@ebid
END
GO
Store Procedure:
In this store procedure I used cursor
CREATE PROCEDURE Pageing
@pagenumber int, --5
@pagesize int --5
AS
BEGIN
declare @srec int --starting record 21
declare @erec int --ending record 21
declare @sbid int --starting book id
declare @ebid int --ending record
declare @rc int -- record count
--set @srec=@pagenumber * @pagesize-@pagesize+1
--use any one of the query both are correct above or below
set @srec=(@pagenumber-1)*@pagesize+1
declare c_book scroll cursor for
select bookid from tbbook order by bookid
open c_book
fetch absolute @srec from c_book into @sbid
--Absolute set the pointer everytime at begining
--Relative can be used but that does not put the pointer on begining everytime
select @rc=COUNT(*) from tbbook where bookid>@sbid
if @rc<@pagesize
set @erec=@srec+@rc
else set @erec=@pagenumber*@pagesize
fetch absolute @erec from c_book into @ebid
close c_book
deallocate c_book
select COUNT(*) from tbbook
select * from tbbook where bookid>=@sbid and bookid<=@ebid
END
GO
0 comments:
Post a Comment