Apply paging in procedure


@intPageId int,
@intPageSize int




select * from (
Select     row_number() over (order by  TableA.intID asc ) r,
    TableA.intID,tableA.hName,TableB.Address
 from TableA
  Join TableB on TableA.intid = TableB.intId

  ) A
  where A.r  between ( (@intpageid-1)*@intpagesize)+1 and ((@intpageid-1)*@intpagesize)+@intpagesize



The query in bold text is for paging, and the normal text query is that which returns your records.

OR

SELECT * from PressRelease 
order by CreatedDate desc
OFFSET (@PageID-1)*@PageSize ROWS
FETCH NEXT @PageSize ROWS ONLY

Comments

  1. DECLARE @pageID INT =2
    DECLARE @pagesize INT=10

    SELECT MarketId,MarketName
    FROM dbo.Market
    ORDER BY MarketId
    OFFSET (@pageID-1)*@pagesize ROWS
    FETCH NEXT @pagesize ROWS ONLY

    Offset skips number of rows from top that you mention and
    FETCH NEXT pull number of rows that you mention

    ReplyDelete

Post a Comment

Popular posts from this blog

TSQL To Get All the Names of tables and Databases whose data have changed in last 24 Hours

To Get All the Names of tables and Databases their data have changed in last 24 Hours And Backup those databases