eZeeNow.com

it's your's

New T-SQL features in SQL Server 2012 – OFFSET and FETCH

There are solutions to this problem in other versions of the product in the form of temp tables, ROW_NUMBER() and TOP but I prefer OFFSET and FETCH to the others.
SELECT TOP 10
2 TransactionID
3 , ProductID
4 , TransactionDate
5 , Quantity
6 , ActualCost
7 FROM
8 Production.TransactionHistory;

SELECT
02 TransactionID
03 , ProductID
04 , TransactionDate
05 , Quantity
06 , ActualCost
07 FROM
08 Production.TransactionHistory
09 ORDER BY TransactionDate DESC
10 OFFSET 0 ROWS
11 FETCH NEXT 20 ROWS ONLY;
OFFSET provides a starting row from which to display the result set. FETCH instructs the query to display the number of rows you want in your result set from the OFFSET point.

Note that NEXT or FIRST can be supplied for FETCH and are synonyms for ANSI compatibility. You can also type ROW or ROWS, again they are synonyms for ANSI compatibility.


There are solutions to this problem in other versions of the product in the form of temp tables, ROW_NUMBER() and TOP but I prefer OFFSET and FETCH to the others.There are solutions to this problem in other versions of the product in the form of temp tables, ROW_NUMBER() and TOP but I prefer OFFSET and FETCH to the others.

Comments (1) -

Loading