理解 SSMS 2012 中的“OFFSET/FETCH" [英] Making sense of 'OFFSET/FETCH' in SSMS 2012
问题描述
今天刚刚安装了 Microsoft SQL Server Management Studio 2012.在熟悉 ORDER BY 的分页功能添加时,我一直遇到这个错误:
Just installed Microsoft SQL Server Management Studio 2012 today. In familiarizing myself with the pagination feature addition of ORDER BY, I keep running into this error:
消息 102,第 15 级,状态 1,第 5 行
OFFSET"附近的语法不正确.
消息 153,第 15 级,状态 2,第 6 行
FETCH 语句中选项 NEXT 的使用无效.
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'OFFSET'.
Msg 153, Level 15, State 2, Line 6
Invalid usage of the option NEXT in the FETCH statement.
这是我的查询:
SELECT SingleWomansName, NumberOfCats
FROM CatLadies
WHERE NumberOfCats > 1
ORDER BY NumberOfCats
OFFSET 10 ROWS
FETCH NEXT 5 ROWS ONLY
我看过很多语法相似的操作指南文章.是什么赋予了?
I've seen plenty of how-to articles with similar syntax. What gives?
http://msdn.microsoft.com/en-us/library/gg699618.aspx
推荐答案
您确定您已连接到 SQL Server 2012 数据库吗?以下作品:
Are you positive you are connected to a SQL Server 2012 database? The following works:
Select Name, CatCount
From CatLadies
Order By Name
Offset 2 Rows
Fetch Next 2 Rows Only
当我切换到 SQL Server 2008 时,我确实收到了您看到的错误
I do get the error you are seeing when I switch to SQL Server 2008
使用 SQL Server 2008 的 SQL Fiddle
这篇关于理解 SSMS 2012 中的“OFFSET/FETCH"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!