A SQL sample for pager

Published on Friday, March 18, 2011

The best way for pager of searching result is use pager in Database side, use stored procedure:

Here is a sample:

SELECT TOP pageSize *
From  [TestDB].[dbo].[USER_EVENTS_LOG]
Where [LogEventsUserID] not in 
(select top pageSize * pageID [LogEventsUserID]
  order by CreateTime  desc)
  order by CreateTime desc

(the pageID start from 0 above, and also it is descent order)