SQLProNews This is an iEntry Publication

Advertising, Headlines, Signup
SQLProNews
SecurityProNews
ITmanagement








Emulating LIMIT With MSSQL 2005

By Daniele Salatti
Expert Author
Article Date: 2008-09-16

I don't like MSSQL, I prefer MySQL, but many times I have to deal with it at work. Lots of developers, including me and my co-worker Enrico, hate that Microsoft SQL hasn't something like MySQL's LIMIT(from, to). With some new T-SQL commands in Miscrosoft SQL Server 2005 there is a not-so-simple solution.

  1. DECLARE @rowsperpage INT
  2.  
  3. DECLARE @start INT
  4.  
  5. SET @start = 100
  6. SET @rowsperpage = 10
  7.  
  8. SELECT * FROM
  9. (
  10. SELECT row_number() OVER (ORDER BY column) AS rownum, column2, column3, .... columnX
  11. FROM   table) AS S
  12. WHERE S.rownum BETWEEN (@start+1) AND (@start + @rowsperpage)

What about performances? Take a look at the images below!





Comments


About the Author:
Daniele Salatti is a 23 years old Italian guy. Informatic Engineering student at the University of Pisa, he is a passionate Linux user. Check out his blog at Salatti.net.




SQLProNews is an iEntry, Inc. ® publication - All Rights Reserved Privacy Policy and Legal
Emulating LIMIT with MSSQL 2005