您的位置:首页 > 数据库

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

2014-02-15 17:52 1136 查看

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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐