Paging in SQL Server

declare @pagesize int
set @pagesize =25

declare @pagenumber int
set @pagenumber =2

declare @from int
set @from = (@pagenumber-1)*@pagesize+1
declare @to int
set @to = @from+@pagesize-1

select @from ,@to
SELECT * FROM ( SELECT * from Employee_tbl ,ROW_NUMBER() OVER (ORDER BY EmployeeID) as rownum FROM Employee_tbl )
seq WHERE seq.rownum BETWEEN @from AND @to ORDER BY seq.rownum

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s