<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Sorting and Paging Recordsets in SQL Server</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx</link><description>Here's a stored procedure that I use for sorting and paging large recordsets in SQL Server, as opposed to using the more common and terribly inefficient entire dataset approach in .NET. It certainly doesn't matter much in the little classroom examples</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: Sorting and Paging Recordsets in SQL Server</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#2304590</link><pubDate>Fri, 20 Apr 2007 20:48:43 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2304590</guid><dc:creator>PaulWilson</dc:creator><author>PaulWilson</author><description>&lt;p&gt;This was written long before Sql 2005 was around with the RowNumber function. &amp;nbsp;My ORMapper does support using the RowNumber function with Sql 2005 for optimal paging.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2304590" width="1" height="1"&gt;</description></item><item><title>re: Sorting and Paging Recordsets in SQL Server</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#2304266</link><pubDate>Fri, 20 Apr 2007 19:47:22 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2304266</guid><dc:creator>Olavo Neto</dc:creator><author>Olavo Neto</author><description>&lt;p&gt;Have you ever consider this?&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://aspnet.4guysfromrolla.com/articles/032206-1.aspx"&gt;http://aspnet.4guysfromrolla.com/articles/032206-1.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2304266" width="1" height="1"&gt;</description></item><item><title>re: Sorting and Paging Recordsets in SQL Server</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#1002873</link><pubDate>Thu, 23 Nov 2006 03:29:32 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:1002873</guid><dc:creator>Jacqueline</dc:creator><author>Jacqueline</author><description>&lt;p&gt;I found that this did not work when performing a descending sort on the second page of a multipage recordset. However adding an additional parameter for sort order and only calling it on the outermost sql statement fixed the issue.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=1002873" width="1" height="1"&gt;</description></item><item><title>PageCount</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#461982</link><pubDate>Tue, 01 Aug 2006 16:57:35 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:461982</guid><dc:creator>Daniel Martinez</dc:creator><author>Daniel Martinez</author><description>This is a great SP and just what I was looking for. I know this is a dumb question...I don't understand how to get the recordset pagecount in ASP. I see the pagecount being returned when I execute the SP in a new query...&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=461982" width="1" height="1"&gt;</description></item><item><title>re: Sorting and Paging Recordsets in SQL Server</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#204715</link><pubDate>Mon, 02 Aug 2004 06:06:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:204715</guid><dc:creator>Resa</dc:creator><author>Resa</author><description>I'm using sql server, and the NextResult method doesn't work, is there another way, i mean using sql server? thanks&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=204715" width="1" height="1"&gt;</description></item><item><title>re: Sorting and Paging Recordsets in SQL Server</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#198283</link><pubDate>Tue, 27 Jul 2004 09:59:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:198283</guid><dc:creator>Paul Wilson</dc:creator><author>Paul Wilson</author><description>Assuming you're using .NET and a DataReader then the NextResult method is what you want.  If you are using a .NET DataSet then you will look at the second table, i.e. .Tables[1].&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=198283" width="1" height="1"&gt;</description></item><item><title>Taking the value of PageCount</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#197890</link><pubDate>Tue, 27 Jul 2004 05:59:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:197890</guid><dc:creator>Resa</dc:creator><author>Resa</author><description>Excuse me but i have never used a stored procedure before, and although your code works great (thanks a lot by the way :)) i want to ask how can i get the PageCount value from the second table generated by ur stored procedure? Thank you very much in advance :)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=197890" width="1" height="1"&gt;</description></item><item><title>re: Sorting and Paging Recordsets in SQL Server</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#189788</link><pubDate>Wed, 21 Jul 2004 11:29:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:189788</guid><dc:creator>Jonny</dc:creator><author>Jonny</author><description>I believe I read somewhere the sp_executesql will compile the dynamic query and create an execution plan for it.  This may speed this up a bit if the same exact query is executed.&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=189788" width="1" height="1"&gt;</description></item><item><title>re: Sorting and Paging Recordsets in SQL Server</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#177256</link><pubDate>Thu, 08 Jul 2004 13:42:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:177256</guid><dc:creator>Paul Wilson</dc:creator><author>Paul Wilson</author><description>I actually just got done reading &lt;a target="_new" href="http://codeproject.com/aspnet/paginglarge.asp"&gt;http://codeproject.com/aspnet/paginglarge.asp&lt;/a&gt; -- and I may switch what I use.  I've never heard any complaints, but it does look like there are better solutions.&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=177256" width="1" height="1"&gt;</description></item><item><title>re: Sorting and Paging Recordsets in SQL Server</title><link>http://weblogs.asp.net/pwilson/archive/2003/10/10/31456.aspx#177248</link><pubDate>Thu, 08 Jul 2004 13:34:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:177248</guid><dc:creator>senkwe</dc:creator><author>senkwe</author><description>Has anybody tried this for tables with a few million rows yet? Thanks.&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=177248" width="1" height="1"&gt;</description></item></channel></rss>