I want to run this query on my SQL Server as follows:
Microsoft SQL Server Management Studio 10.50.1600.1
But it can't recognize the OFFSET and so shows ERROR?
SELECT * FROM dbo.tbl_MatchDetail
ORDER BY MatchDetailID
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY;
OFFSET FETCH is a feature added to the ORDER BY clause beginning with the SQL Server 2012 edition. It can be used to extract a specific number of rows starting from a specific index. As an example, we have a query that returns 40 rows and we need to extract 10 rows from the 10th row: 1.
The following are the syntax that illustrates the use of OFFSET and FETCH clause: SELECT * FROM table_name. ORDER BY columns [ASC |DESC] OFFSET no_of_rows_to_skip.
FETCH is an SQL command used along with ORDER BY clause with an OFFSET(Starting point) to retrieve or fetch selected rows sequentially using a cursor that moves and processes each row one at a time till the number of rows mentioned in the query are displayed. With FETCH the OFFSET clause is mandatory.
OFFSET FETCH is a new feature added to Sql Server 2012 and does not exist in Sql Server 2008.
Please be aware you will get an error even in 2014 if you don't have an order by. The offset must follow an order by statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With