<?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>SqlServer 2005 paging: there IS a generic wrapper query possible</title><link>http://weblogs.asp.net/fbouma/archive/2007/06/05/sqlserver-2005-paging-there-is-a-generic-wrapper-query-possible.aspx</link><description>(the Name field in the queries below is without [ and ] brackets, because CS currently goes bezerk because of these. Don't know why, but apparently a glitch somewhere.) Recently, I wrote a blogpost about SqlServer 2005 paging, called API's and production</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>links for 2007-06-07 &amp;raquo; mhinze.com</title><link>http://weblogs.asp.net/fbouma/archive/2007/06/05/sqlserver-2005-paging-there-is-a-generic-wrapper-query-possible.aspx#2753661</link><pubDate>Thu, 07 Jun 2007 15:27:03 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2753661</guid><dc:creator>links for 2007-06-07 » mhinze.com</dc:creator><author>links for 2007-06-07 » mhinze.com</author><description>&lt;p&gt;Pingback from &amp;nbsp;links for 2007-06-07 &amp;amp;raquo; mhinze.com&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2753661" width="1" height="1"&gt;</description></item><item><title>re: SqlServer 2005 paging: there IS a generic wrapper query possible</title><link>http://weblogs.asp.net/fbouma/archive/2007/06/05/sqlserver-2005-paging-there-is-a-generic-wrapper-query-possible.aspx#2734768</link><pubDate>Tue, 05 Jun 2007 21:12:25 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2734768</guid><dc:creator>Sean</dc:creator><author>Sean</author><description>Careful, working around TOP 100 PERCENT might be going around a technical limitation, better hit that speed dial button to MS EULA Central&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2734768" width="1" height="1"&gt;</description></item><item><title>re: SqlServer 2005 paging: there IS a generic wrapper query possible</title><link>http://weblogs.asp.net/fbouma/archive/2007/06/05/sqlserver-2005-paging-there-is-a-generic-wrapper-query-possible.aspx#2733228</link><pubDate>Tue, 05 Jun 2007 16:15:53 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2733228</guid><dc:creator>FransBouma</dc:creator><author>FransBouma</author><description>&lt;p&gt;Oren, indeed! that's indeed a bummer I didn't think of. Thanks for the heads up. &lt;/p&gt;
&lt;p&gt;Hmm... Indeed something to think of when writing paging queries.. :/ &lt;/p&gt;
&lt;p&gt;(the layout of your reply is messed up, sorry for that, the approval api of CS is still a bit shaky in some areas apparently, so it then removes linebreaks)&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2733228" width="1" height="1"&gt;</description></item><item><title>re: SqlServer 2005 paging: there IS a generic wrapper query possible</title><link>http://weblogs.asp.net/fbouma/archive/2007/06/05/sqlserver-2005-paging-there-is-a-generic-wrapper-query-possible.aspx#2733174</link><pubDate>Tue, 05 Jun 2007 15:47:19 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2733174</guid><dc:creator>Ayende Rahien</dc:creator><author>Ayende Rahien</author><description>Frans,
This works:&lt;br /&gt;
select id id, anotherid id from customers&lt;br /&gt;
This gives syntax error:&lt;br /&gt;
WITH __actualSet AS &lt;br /&gt;
( &lt;br /&gt;
   SELECT *, &lt;br /&gt;
       ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) AS __rowcnt &lt;br /&gt;
   FROM &lt;br /&gt;
   (&lt;br /&gt;
      select id id, anotherid id from customers&lt;br /&gt;
   ) AS _tmpSet&lt;br /&gt;
) &lt;br /&gt;
SELECT * FROM __actualSet &lt;br /&gt;
WHERE [__rowcnt] &amp;gt; 0 &lt;br /&gt;
   AND [__rowcnt] &amp;lt;= 16&lt;br /&gt;
ORDER BY [__rowcnt] ASC&lt;br /&gt;
&lt;br /&gt;
The original query is WTF, I agree, but I run into this issue yesterday
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2733174" width="1" height="1"&gt;</description></item><item><title>re: SqlServer 2005 paging: there IS a generic wrapper query possible</title><link>http://weblogs.asp.net/fbouma/archive/2007/06/05/sqlserver-2005-paging-there-is-a-generic-wrapper-query-possible.aspx#2732898</link><pubDate>Tue, 05 Jun 2007 13:38:13 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2732898</guid><dc:creator>FransBouma</dc:creator><author>FransBouma</author><description>&lt;p&gt;Yes the TOP 100 PERCENT is indeed not working! :) I found that out myself right after posting this and tried a DESC sort instead of an ASC sort.. it didn't give the results I was after. Very odd. (So I removed that remark ;))&lt;/p&gt;
&lt;p&gt;The ROW_NUMBER trick &amp;nbsp;inside the query is indeed an option, but that is more cumbersome to create, and is a bit less of a 'wrapper' for a query to page. &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2732898" width="1" height="1"&gt;</description></item><item><title>re: SqlServer 2005 paging: there IS a generic wrapper query possible</title><link>http://weblogs.asp.net/fbouma/archive/2007/06/05/sqlserver-2005-paging-there-is-a-generic-wrapper-query-possible.aspx#2732866</link><pubDate>Tue, 05 Jun 2007 13:22:12 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2732866</guid><dc:creator>David Markle</dc:creator><author>David Markle</author><description>Frans:

Great article.  I just did something quite close to this myself at work for a coworker.  I wonder how well it scales to large numbers of rows.  

The only thing that you should be careful of is that TOP 100 PERCENT doesn&amp;#39;t really work in SQL 2005.  Take a look at my (non-inflammatory) blog entry:

&lt;a href="http://executioniseverything.blogspot.com/2007_01_01_archive.html"&gt;
http://executioniseverything.blogspot.com/2007_01_01_archive.html
&lt;/a&gt;

Scary new behavior, huh!?

Actually, instead of TOP, you can use ROW_NUMBER() with an ORDER BY once again, inside your CTE to produce a properly ordered set -- that&amp;#39;ll do the trick.

&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2732866" width="1" height="1"&gt;</description></item></channel></rss>