Tidbit Tuesday: Paginating in MSSQL

I don’t really work with MSSQL very much and was wondering how to do pagination similar to doing it in MySQL with the LIMIT command.  It’s MUCH harder in MSSQL, but here is how you do it:

SELECT * FROM
 (SELECT TOP [size_of_record_set] * FROM
 (SELECT TOP [end_record] * FROM [table] ORDER BY [field] ASC) AS tbl1 ORDER BY [field] DESC
 ) AS tbl2
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • MySpace
  • Twitter
  • Sphinn
  • Reddit

1 comment to Tidbit Tuesday: Paginating in MSSQL

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Sponsor:

SponsoredTweets referral badge