Friday, October 7, 2011

SQLServer Denali : OFFSET & NEXT Keywords

 

Hi All,

 

I found these two new & very useful keywords in SQLServer Denali

OFFSET & NEXT

 

SELECT *
FROM [Order Details]
ORDER BY [Order ID]
OFFSET 20 ROWS
FETCH NEXT 7 ROWS ONLY

 

 

Above script returns records 21 to 27 from the tables [Order Details]. OFFSET clause will skip the first 20 rows and then returns 7 rows. Please note, this T-SQL will throw error if ORDER BY is not used in the query.

 

Reference: PinalDave's blog

http://blog.sqlauthority.com/2011/10/07/sql-server-server-side-paging-in-sql-server-ce-compact-edition/

 

Namaste!

Anugrah