Hi, what about such solution?
DECLARE @pageNumber INT
DECLARE @rowsOnPage INT
SET @rowsOnPage=5
SET @pageNumber=2
DECLARE @totalItemsToSelect INT
SET @totalItemsToSelect=@rowsOnPage * @pageNumber
SELECT TOP (@rowsOnPage) * FROM MainTrans WHERE ID IN
(
SELECT TOP (@totalItemsToSelect) ID FROM MainTrans ORDER BY ID DESC
) ORDER BY ID ASC
it looks much shorter.
Thanks,
Kiryl
P.S. of course this solution works only if you have identity column. in my opinion identity column is a must for paging, moreover this approach works for any database not only for MS SQL