sql server - Paging in T-SQL -


alter procedure [dbo].[getmessages]     -- add parameters stored procedure here     @lastrow int,     @sort varchar(9) begin     -- insert statements procedure here     declare @startrow int,@endrow int     select @startrow = (@lastrow + 1), @endrow = (@lastrow + 6)  ;with cte (select row_number() on (order         case when @sort = 'votes1' m.votes end desc,         case when @sort = 'votes2' m.votes end asc       ) rows,       m.message,       m.messageid,       totalcount = count(m.messageid) on ( partition null)           tblmessages m           m.deleted != 1       )      select *       cte rows between @startrow , @endrow     order rows end 

so proc use paging on front end can pass in last row saw, , when click "load more", starts next row , gets next 6. well, not want previous 6, passing in id, if see 6, go next six, , want see previous 6 again.

how modify proc that?

you don't.

instead, modify code. key in proc @lastrow. when execute first time i'm assuming @lastrow = 0. if go forward, executing value of 6.

to go backward, pass current value - 6. example, if you're on page 20, @lastrow going 114. subtract 6 in code , call proc again.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -