<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Custom Paging &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/custom-paging/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Fri, 29 Sep 2017 06:03:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server 2012: Custom paging using OFFSET and FETCH NEXT</title>
		<link>https://www.dbrnd.com/2016/01/sql-server-2012-custom-paging-using-offset-and-fetch-next/</link>
					<comments>https://www.dbrnd.com/2016/01/sql-server-2012-custom-paging-using-offset-and-fetch-next/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 24 Jan 2016 17:22:28 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Custom Paging]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[offset]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1380</guid>

					<description><![CDATA[In this post, I am sharing a demo on SQL Server 2012 Pagination or Custom paging query using OFFSET and FETCH. Whenever thousands or millions of rows are returning from a database at that time paging is required. Using custom paging, we can return only limited data for a particular page. For example, database stored [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F01%2Fsql-server-2012-custom-paging-using-offset-and-fetch-next%2F&amp;linkname=SQL%20Server%202012%3A%20Custom%20paging%20using%20OFFSET%20and%20FETCH%20NEXT" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F01%2Fsql-server-2012-custom-paging-using-offset-and-fetch-next%2F&amp;linkname=SQL%20Server%202012%3A%20Custom%20paging%20using%20OFFSET%20and%20FETCH%20NEXT" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F01%2Fsql-server-2012-custom-paging-using-offset-and-fetch-next%2F&amp;linkname=SQL%20Server%202012%3A%20Custom%20paging%20using%20OFFSET%20and%20FETCH%20NEXT" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F01%2Fsql-server-2012-custom-paging-using-offset-and-fetch-next%2F&amp;linkname=SQL%20Server%202012%3A%20Custom%20paging%20using%20OFFSET%20and%20FETCH%20NEXT" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F01%2Fsql-server-2012-custom-paging-using-offset-and-fetch-next%2F&amp;linkname=SQL%20Server%202012%3A%20Custom%20paging%20using%20OFFSET%20and%20FETCH%20NEXT" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F01%2Fsql-server-2012-custom-paging-using-offset-and-fetch-next%2F&amp;linkname=SQL%20Server%202012%3A%20Custom%20paging%20using%20OFFSET%20and%20FETCH%20NEXT" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F01%2Fsql-server-2012-custom-paging-using-offset-and-fetch-next%2F&#038;title=SQL%20Server%202012%3A%20Custom%20paging%20using%20OFFSET%20and%20FETCH%20NEXT" data-a2a-url="https://www.dbrnd.com/2016/01/sql-server-2012-custom-paging-using-offset-and-fetch-next/" data-a2a-title="SQL Server 2012: Custom paging using OFFSET and FETCH NEXT"></a></p><p>In this post, I am sharing a demo on SQL Server 2012 Pagination or Custom paging query using OFFSET and FETCH.</p>
<blockquote><p>Whenever thousands or millions of rows are returning from a database at that time paging is required.<br />
Using custom paging, we can return only limited data for a particular page.</p></blockquote>
<p>For example, database stored procedure returned 10,00,00 records at one call. How can you arrange this many data into the application grid or any report?</p>
<p>In this kind of requirement, database paging is playing an important role.<br />
The Application has to call a stored procedure using two main parameters:</p>
<blockquote><p>Page number<br />
Page size</p></blockquote>
<p>SQL Server 2012 introduced powerful <b>FETCH </b>and <b>OFFSET </b>features.</p>
<p><b>FETCH and OFFSET retires only small portion of rows from the primary result set.</b></p>
<p>Using FETCH, you can set a total number of rows. </p>
<p>Using OFFSET, you can skip some rows.</p>
<p><strong>First, create a sample table and insert sample 10000 records. </strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_SamplePaging 
(
	EmpID INT IDENTITY(1,1)
	,EmpName VARCHAR(250)
)
GO

INSERT INTO tbl_SamplePaging(EmpName) 
VALUES ('ABCD' + CAST((SELECT MAX(EmpID) FROM tbl_SamplePaging) AS VARCHAR))
GO 10000</pre><p>
<p><strong>The custom paging query using PageSize and PageNumber parameters:</strong></p><pre class="crayon-plain-tag">DECLARE
  @PageSize INT = 10,
  @PageNumber  INT = 1;

SELECT 
	COUNT(1) OVER() AS TotalCount
	,EmpID
	,EmpName	
FROM tbl_SamplePaging
ORDER BY EmpID 
	OFFSET (@PageNumber-1)*@PageSize ROWS
	FETCH NEXT @PageSize ROWS ONLY</pre><p>
<p><strong>The result of first page with 10 records:</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerCustomPaging.png" rel="attachment wp-att-1384"><img decoding="async" class="alignnone wp-image-1384 size-full" title="SQL Server Custom Paging" src="https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerCustomPaging.png" alt="SQL Server Custom Paging" width="219" height="224" srcset="https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerCustomPaging.png 219w, https://www.dbrnd.com/wp-content/uploads/2016/01/SQLServerCustomPaging-150x153.png 150w" sizes="(max-width: 219px) 100vw, 219px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/01/sql-server-2012-custom-paging-using-offset-and-fetch-next/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
