MS-SQL 错误: The offset specified in a OFFSET clause may not be negative

Example 1 : (Fetch clause must be greater than zero)

USE AdventureWorks2012

GO

SELECT * FROM [HumanResources].[vEmployee]

ORDER BY [JobTitle]

OFFSET 10 ROWS

FETCH NEXT 0 ROWS ONLY

--OUTPUT

Msg 10744, Level 15, State 1, Line 4
The number of rows provided for a FETCH clause must be greater then zero.

Example 2 : (Offset clause must have integer only)

USE AdventureWorks2012

GO

SELECT * FROM [HumanResources].[vEmployee]

ORDER BY [JobTitle]

OFFSET 1.1 ROWS

FETCH NEXT 10 ROWS ONLY

--OUTPUT

Msg 10743, Level 15, State 1, Line 3
The number of rows provided for an OFFSET clause must be an integer.

Example 3 : (Offset clause may not be negative)

USE AdventureWorks2012

GO

SELECT * FROM [HumanResources].[vEmployee]

ORDER BY [JobTitle]

OFFSET -10 ROWS

FETCH NEXT 10 ROWS ONLY

--OUTPUT

Msg 10742, Level 15, State 1, Line 3
The offset specified in an OFFSET clause may not be negative.

Example 4 : (A Top cannot be used in the same query or sub query as an offset.)

USE AdventureWorks2012

GO

SELECT Top 5 * FROM [HumanResources].[vEmployee]

ORDER BY [JobTitle]

OFFSET 10 ROWS

FETCH NEXT 10 ROWS ONLY

--OUTPUT

Msg 10741, Level 15, State 2, Line 2
A TOP cannot be used in the same query or sub-query as an OFFSET.

原文: http://raresql.com/tag/the-offset-specified-in-a-offset-clause-may-not-be-negative/

posted @ 2014-02-15 17:52  DukeCheng  阅读(1937)  评论(0编辑  收藏  举报