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.
Leave a Reply