Condividi tramite


SKIP (Entity SQL)

You can perform physical paging by using the SKIP sub-clause in the ORDER BY clause. SKIP cannot be used separately from the ORDER BY clause.

[ SKIP n ]

Arguments

  • n
    The number of items to skip.

Remarks

If a SKIP expression sub-clause is present in an ORDER BY clause, the results will be sorted according the sort specification and the result set will include rows starting from the next row immediately after the SKIP expression. For example, SKIP 5 will skip the first five rows and return from the sixth row forward.

Note

An Entity SQL query is invalid if both the TOP modifier and the SKIP sub-clause are present in the same query expression. The query should be rewritten by changing the TOP expression to the LIMIT expression.

Note

In SQL Server 2000, using SKIP with ORDER BY on non-key columns might return incorrect results. More than the specified number of rows might be skipped if the non-key column has duplicate data in it. This is due to how SKIP is translated for SQL Server 2000. For example, in the following code more than five rows might be skipped if E.NonKeyColumn has duplicate values:

SELECT [E] FROM Container.EntitySet AS [E] ORDER BY [E].[NonKeyColumn] DESC SKIP 5L

Example

The following Entity SQL query uses the ORDER BY operator with SKIP to specify the sort order used on objects returned in a SELECT statement. The query is based on the AdventureWorks Sales Model. To compile and run this query, follow these steps:

  1. Follow the procedure in How to: Execute a Query that Returns StructuralType Results (EntityClient).

  2. Pass the following query as an argument to the ExecuteStructuralTypeQuery method:

SELECT VALUE p FROM AdventureWorksEntities.Product 
    AS p order by p.ListPrice SKIP(70)

The output is shown below:

ProductID: 392
Name: Hex Nut 3
ProductNumber: HN-6320
MakeFlag: False
ProductID: 393
Name: Hex Nut 14
ProductNumber: HN-7161
MakeFlag: False
ProductID: 394
Name: Hex Nut 15
ProductNumber: HN-7162
MakeFlag: False
ProductID: 395
Name: Hex Nut 4
ProductNumber: HN-8320
MakeFlag: False
ProductID: 396
Name: Hex Nut 18
ProductNumber: HN-9161
MakeFlag: False

See Also

Tasks

How to: Page Through Query Results (Entity Framework)

Reference

ORDER BY (Entity SQL)
TOP (Entity SQL)

Concepts

Paging (Entity SQL)