SQL Server 2014 - Offset with fetch next












1














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









share|improve this question
























  • 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










  • 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
















1














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









share|improve this question
























  • 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










  • 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














1












1








1







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









share|improve this question















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






sql-server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 14:28









marc_s

571k12811031251




571k12811031251










asked Nov 19 '18 at 14:18









Captai-N

102211




102211












  • 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










  • 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


















  • 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










  • 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
















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












1 Answer
1






active

oldest

votes


















1














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;





share|improve this answer























  • 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











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
});


}
});














draft saved

draft discarded


















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









1














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;





share|improve this answer























  • 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
















1














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;





share|improve this answer























  • 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














1












1








1






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;





share|improve this answer














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;






share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory