paginate-a-board-list-with-row_number-in-sql-server.md
devcondadatabasepaginate-a-board-list-with-row_number-in-sql-server.md

Paginate a Board List with ROW_NUMBER() in SQL Server

Written by

in

SQL Server board list paging with ROW_NUMBER() (the original title typo was RWO_NUMBER).

select * from(
  select ROW_NUMBER() over(order by ref desc, step asc, num desc) as rnum, *
  from table_name
) T
where T.rnum>=(startrow) and T.rnum<=(endrow)

ref is the reference number of the original post. step is reply order (0 for the question/root post, 1 for a reply).

Figuring out this one query took more effort than it should have. Hang in there, fellow SQL Server users.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *