sql server - Stored procedure for pagination is not working -
i implementing pagination in asp.net application. this, have created stored procedure records communitypost
table. stored procedure not working correctly. not return records.
my stored procedure is:
alter procedure [dbo].[communitypostloadallpaged] ( @pageindex int = 0, @pagesize int = 2147483644, @totalrecords int = null output ) begin declare @sql nvarchar(max) --paging declare @pagelowerbound int declare @pageupperbound int declare @rowstoreturn int set @rowstoreturn = @pagesize * (@pageindex + 1) set @pagelowerbound = @pagesize * @pageindex set @pageupperbound = @pagelowerbound + @pagesize + 1 create table #displayordertmp ( [id] int identity (1, 1) not null, [communitypostid] int not null ) set @sql = ' insert #displayordertmp ([communitypostid]) select p.id communitypost p (nolock)' create table #pageindex ( [indexid] int identity (1, 1) not null, communitypostid int not null ) insert #pageindex (communitypostid) select communitypostid #displayordertmp group communitypostid order min([id]) select * #pageindex --total records set @totalrecords = @@rowcount select * #displayordertmp drop table #displayordertmp select * #pageindex --return products select top (@rowstoreturn) p.* #pageindex [pi] inner join dbo.communitypost p (nolock) on p.id = [pi].communitypostid [pi].indexid > @pagelowerbound , [pi].indexid < @pageupperbound order [pi].indexid drop table #pageindex end
table schema of communitypost
table :
columnname datatype ================================ id int sharerid int text nvarchar(max) published bit createdonutc datetime
how can communitypost
records pagination implementation?
please me.
thank in advance.
try this
alter procedure [dbo].[communitypostloadallpaged] ( @pageindex int = 0, @pagesize int = 50, @totalrecords int = null output ) begin declare @inendrow int ,@instartrow int create table #displayordertmp ( [id] int identity (1, 1) not null, [inrownum] int primary key, [communitypostid] int not null ) insert #displayordertmp ([communitypostid]) select row_number() over(order p.id asc), p.id communitypost p (nolock) select @totalrecords = count(1) ,@inendrow = ((@pageindex + @pagesize ) + 1) ,@instartrow = @pageindex #displayordertmp d (nolock) select * #displayordertmp d (nolock) d.inrownum > @instartrow , d.inrownum < @inendrow end
Comments
Post a Comment