MSSQL query generator uses OFFSET FETCH clause only supported in SQL Server 2012 and up
See original GitHub issueThe query generator uses an OFFSET FETCH clause to apply the offset and limit parameters, which works fine in SQL Server 2012 and newer, but is unsupported in older versions of SQL Server.
I found this when I tried to use findById against an SQL Server 2008 R2 database. The server came back with this error message:
Invalid usage of the option NEXT in the FETCH statement.
Looking at the code, it looks like this will also happen when using findOne, or when the offset or limit options are used in a findAll, findAndCount, etc.
So the offset and limit functionality should either be changed to use a syntax supported by all SQL Server versions, or there should be logic to fall back to an old method when a version before 2012 is detected. Or the docs could be updated to specify that only versions newer than 2012 are supported.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:26 (8 by maintainers)

Top Related StackOverflow Question
@accugopher You do realize that nobody got paid a dime to implement sql support? If you were so annoyed by it, why didn’t it do something to fix it?
I know that things are different in the MS world, but do you really expect someone to go to the effort to support a version that was released more than 10 years ago, and reached its end of life last year? Especially when they didn’t need it? Should we have refused to merge the code, because it did not support any verison of sql server released within the last 30 years?
More to the point: I don’t have personal experience with sql server, but judging from https://github.com/sequelize/sequelize/pull/5616/files and https://github.com/sequelize/sequelize/blob/8cbd3750f5f8034cc53096de6ddb43593ba1c983/lib/dialects/mssql/query-generator.js#L769 it seems that we do indeed try to support older versions of sql server. We try to identify the version at startup, but perhaps it’s failing? Perhaps try setting
options.databaseVersionmanually in the sequelize constructor (It has to be a semver valid string, in this case anything <11.0.0should work.That is apparently what this means. I just spent the last few weeks on one of the worst projects I’ve ever had in 30+ years of engineering, and largely because this package didn’t support SQL Server 2005. If I had had the time, I would have fixed this myself, but as it stands right now, Sequelize is worthless for use with Microsoft SQL Server the way this has been implemented. To only support SQL Server 2012 or newer is probably the laziest thing I’ve ever seen an engineer do in my years of building and supporting systems, but hey, it fixed their problem, screw you lot, fix it yourself.