Sort persons by their first name, ignore the 5 first and get next 5
Actual behaviour:
Error:
ERROR Invalid usage of the option NEXT in the FETCH statement. 11:46:56
at handleError (node_modules\mssql\lib\tedious\request.js:384:15)
at Connection.emit (node:events:390:28)
at Connection.emit (node_modules\tedious\lib\connection.js:1048:18)
at RequestTokenHandler.onErrorMessage (node_modules\tedious\lib\token\handler.js:365:21)
at Readable.<anonymous> (node_modules\tedious\lib\token\token-stream-parser.js:26:33)
at Readable.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Readable.push (node:internal/streams/readable:228:10)
at next (node:internal/streams/from:98:31)
Code:
const bodyParser = require('body-parser')
const app = require('express')()
const sql = require('mssql')
const sqlConfig = {
user: '...',
password: '...',
database: '...',
server: '...',
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000,
},
options: {
encrypt: false,
trustServerCertificate: true, // change to true for local dev / self-signed certs
},
}
app.use(bodyParser.json())
app.get('/getJSON', async (req, res) => {
console.log('req', req.query.test)
const query = `
SELECT id, firstName
FROM persons
ORDER BY firstName
OFFSET 5 ROWS
FETCH NEXT 5 ROWS ONLY
`
console.log(query)
try {
// make sure that any items are correctly URL encoded in the connection string
await sql.connect(sqlConfig)
const result = await sql.query(query)
res.json({ result })
} catch (err) {
console.error(err)
res.send('error ' + err)
}
})
If I run the query in SQL Management Studio, the query run smoothly with no issue.
Software versions
NodeJS: v16.13.2
node-mssql: 9.0.0
SQL Server: Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64)
Expected behaviour:
Sort persons by their first name, ignore the 5 first and get next 5
Actual behaviour:
Error:
Code:
If I run the query in SQL Management Studio, the query run smoothly with no issue.
Software versions