Computer enthusiast interested in software development and security analysis. www.fritzfs.info
Friday, November 13, 2009
T-SQL: alternative to LIMIT clause
In MySQL as well as in PostgreSQL there's a LIMIT clause with which you can specify the offset of starting row and number of total rows that you wish to retrieve. There's no such thing, AFAIK, in T-SQL (SQL Server) so I'm using WITH statement with ROW_NUMBER().
WITH tbl AS
ROW_NUMBER() OVER (ORDER BY id) AS rowNum
WHERE rowNum BETWEEN 5 AND 10