SQL Server 2014 - Offset with fetch next
I'm trying to run this code, but I get the error:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'OFFSET'.
Msg 153, Level 15, State 2, Line 4
Invalid use of the NEXT option in the FETCH statement.
This is my code:
SELECT *
FROM dbp.Expats_Gesamt AS P
ORDER BY P.last_name
OFFSET 10 ROWS
FETCH NEXT 20 ROWS ONLY

add a comment |
I'm trying to run this code, but I get the error:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'OFFSET'.
Msg 153, Level 15, State 2, Line 4
Invalid use of the NEXT option in the FETCH statement.
This is my code:
SELECT *
FROM dbp.Expats_Gesamt AS P
ORDER BY P.last_name
OFFSET 10 ROWS
FETCH NEXT 20 ROWS ONLY

Tag theSQL Server
version that you are using. You can check itselect @@VERSION
.
– Yogesh Sharma
Nov 19 '18 at 14:21
I can't replicate the error on SQL Server 2012, nor on fiddle. dd<>fiddle
– Larnu
Nov 19 '18 at 14:23
Check the compatibility level of your database.OFFSET-FETCH
should only parse correctly at level 110 or higher.
– Jeroen Mostert
Nov 19 '18 at 14:29
usedbo.
instead ofdbp
– IdontKnowEnglish
Nov 19 '18 at 16:01
add a comment |
I'm trying to run this code, but I get the error:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'OFFSET'.
Msg 153, Level 15, State 2, Line 4
Invalid use of the NEXT option in the FETCH statement.
This is my code:
SELECT *
FROM dbp.Expats_Gesamt AS P
ORDER BY P.last_name
OFFSET 10 ROWS
FETCH NEXT 20 ROWS ONLY

I'm trying to run this code, but I get the error:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'OFFSET'.
Msg 153, Level 15, State 2, Line 4
Invalid use of the NEXT option in the FETCH statement.
This is my code:
SELECT *
FROM dbp.Expats_Gesamt AS P
ORDER BY P.last_name
OFFSET 10 ROWS
FETCH NEXT 20 ROWS ONLY


edited Nov 19 '18 at 14:28
marc_s
571k12811031251
571k12811031251
asked Nov 19 '18 at 14:18
Captai-N
102211
102211
Tag theSQL Server
version that you are using. You can check itselect @@VERSION
.
– Yogesh Sharma
Nov 19 '18 at 14:21
I can't replicate the error on SQL Server 2012, nor on fiddle. dd<>fiddle
– Larnu
Nov 19 '18 at 14:23
Check the compatibility level of your database.OFFSET-FETCH
should only parse correctly at level 110 or higher.
– Jeroen Mostert
Nov 19 '18 at 14:29
usedbo.
instead ofdbp
– IdontKnowEnglish
Nov 19 '18 at 16:01
add a comment |
Tag theSQL Server
version that you are using. You can check itselect @@VERSION
.
– Yogesh Sharma
Nov 19 '18 at 14:21
I can't replicate the error on SQL Server 2012, nor on fiddle. dd<>fiddle
– Larnu
Nov 19 '18 at 14:23
Check the compatibility level of your database.OFFSET-FETCH
should only parse correctly at level 110 or higher.
– Jeroen Mostert
Nov 19 '18 at 14:29
usedbo.
instead ofdbp
– IdontKnowEnglish
Nov 19 '18 at 16:01
Tag the
SQL Server
version that you are using. You can check it select @@VERSION
.– Yogesh Sharma
Nov 19 '18 at 14:21
Tag the
SQL Server
version that you are using. You can check it select @@VERSION
.– Yogesh Sharma
Nov 19 '18 at 14:21
I can't replicate the error on SQL Server 2012, nor on fiddle. dd<>fiddle
– Larnu
Nov 19 '18 at 14:23
I can't replicate the error on SQL Server 2012, nor on fiddle. dd<>fiddle
– Larnu
Nov 19 '18 at 14:23
Check the compatibility level of your database.
OFFSET-FETCH
should only parse correctly at level 110 or higher.– Jeroen Mostert
Nov 19 '18 at 14:29
Check the compatibility level of your database.
OFFSET-FETCH
should only parse correctly at level 110 or higher.– Jeroen Mostert
Nov 19 '18 at 14:29
use
dbo.
instead of dbp
– IdontKnowEnglish
Nov 19 '18 at 16:01
use
dbo.
instead of dbp
– IdontKnowEnglish
Nov 19 '18 at 16:01
add a comment |
1 Answer
1
active
oldest
votes
Your error suggests FETCH . . . OFFSET
clause error that means your current version that don't support it or might be version compatibility issue (you can check & set accordingly) however i don't know which version you are using.
So, i would try with subquery
instead that would support for lower version :
select top (20) p.*
from (select top (30) P.*
from dbp.Expats_Gesamt AS P
order by P.last_name
) p
order by P.last_name desc;
Considering that the OP has put "SQL Server 2014" in the question's subject, I suspect the problem is the compatibility level, and not the version of the Software.
– Larnu
Nov 19 '18 at 14:44
@Larnu. . . That i realized on my second last edit made.
– Yogesh Sharma
Nov 19 '18 at 14:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376571%2fsql-server-2014-offset-with-fetch-next%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your error suggests FETCH . . . OFFSET
clause error that means your current version that don't support it or might be version compatibility issue (you can check & set accordingly) however i don't know which version you are using.
So, i would try with subquery
instead that would support for lower version :
select top (20) p.*
from (select top (30) P.*
from dbp.Expats_Gesamt AS P
order by P.last_name
) p
order by P.last_name desc;
Considering that the OP has put "SQL Server 2014" in the question's subject, I suspect the problem is the compatibility level, and not the version of the Software.
– Larnu
Nov 19 '18 at 14:44
@Larnu. . . That i realized on my second last edit made.
– Yogesh Sharma
Nov 19 '18 at 14:46
add a comment |
Your error suggests FETCH . . . OFFSET
clause error that means your current version that don't support it or might be version compatibility issue (you can check & set accordingly) however i don't know which version you are using.
So, i would try with subquery
instead that would support for lower version :
select top (20) p.*
from (select top (30) P.*
from dbp.Expats_Gesamt AS P
order by P.last_name
) p
order by P.last_name desc;
Considering that the OP has put "SQL Server 2014" in the question's subject, I suspect the problem is the compatibility level, and not the version of the Software.
– Larnu
Nov 19 '18 at 14:44
@Larnu. . . That i realized on my second last edit made.
– Yogesh Sharma
Nov 19 '18 at 14:46
add a comment |
Your error suggests FETCH . . . OFFSET
clause error that means your current version that don't support it or might be version compatibility issue (you can check & set accordingly) however i don't know which version you are using.
So, i would try with subquery
instead that would support for lower version :
select top (20) p.*
from (select top (30) P.*
from dbp.Expats_Gesamt AS P
order by P.last_name
) p
order by P.last_name desc;
Your error suggests FETCH . . . OFFSET
clause error that means your current version that don't support it or might be version compatibility issue (you can check & set accordingly) however i don't know which version you are using.
So, i would try with subquery
instead that would support for lower version :
select top (20) p.*
from (select top (30) P.*
from dbp.Expats_Gesamt AS P
order by P.last_name
) p
order by P.last_name desc;
edited Nov 19 '18 at 14:31
answered Nov 19 '18 at 14:25


Yogesh Sharma
28.2k51335
28.2k51335
Considering that the OP has put "SQL Server 2014" in the question's subject, I suspect the problem is the compatibility level, and not the version of the Software.
– Larnu
Nov 19 '18 at 14:44
@Larnu. . . That i realized on my second last edit made.
– Yogesh Sharma
Nov 19 '18 at 14:46
add a comment |
Considering that the OP has put "SQL Server 2014" in the question's subject, I suspect the problem is the compatibility level, and not the version of the Software.
– Larnu
Nov 19 '18 at 14:44
@Larnu. . . That i realized on my second last edit made.
– Yogesh Sharma
Nov 19 '18 at 14:46
Considering that the OP has put "SQL Server 2014" in the question's subject, I suspect the problem is the compatibility level, and not the version of the Software.
– Larnu
Nov 19 '18 at 14:44
Considering that the OP has put "SQL Server 2014" in the question's subject, I suspect the problem is the compatibility level, and not the version of the Software.
– Larnu
Nov 19 '18 at 14:44
@Larnu. . . That i realized on my second last edit made.
– Yogesh Sharma
Nov 19 '18 at 14:46
@Larnu. . . That i realized on my second last edit made.
– Yogesh Sharma
Nov 19 '18 at 14:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376571%2fsql-server-2014-offset-with-fetch-next%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Tag the
SQL Server
version that you are using. You can check itselect @@VERSION
.– Yogesh Sharma
Nov 19 '18 at 14:21
I can't replicate the error on SQL Server 2012, nor on fiddle. dd<>fiddle
– Larnu
Nov 19 '18 at 14:23
Check the compatibility level of your database.
OFFSET-FETCH
should only parse correctly at level 110 or higher.– Jeroen Mostert
Nov 19 '18 at 14:29
use
dbo.
instead ofdbp
– IdontKnowEnglish
Nov 19 '18 at 16:01