How To Access The Output Parameter In Node Mssql?
` request.input('xyz',sql.Int,1); request.input('abc',sql.Numeric,2); request.output('pqr',sql.Int); request.output('def',sql.Char); request.execute('[StoredProc
Solution 1:
request.parameters.pqr.value
and request.parameters.def.value
Got the answer , so sharing it :)
Solution 2:
Actually the method described above did not work for me using "mssql": "^4.3.0"
.
I had to use the result object returned by the promise and extract the parameters from the output
object. Something like:
res.output.
Here is the sample code which worked for me:
poolPromise
.then(conn => conn.request())
.then(request => {
const forecastName = forecastDefinition.name;
// Input parameters
request.input('forecastName', sql.VarChar(50), forecastName);
...
// Output parameters
request.output('actualYear', sql.Int);
request.output('actualMonth', sql.Int);
...
return request.execute('[dbo].[' + generateForecastProcedure + ']')
})
.then((res, err) => {
if (err) {
console.log(`${generateForecastProcedure} error: `, err);
} else {
console.log(`${generateForecastProcedure} success: `, res);
// Callback to deal with further processing.
const output = (res.output || {});
const actualYear = output.actualYear;
const actualMonth = output.actualMonth;
callback(forecastDefinition, actualYear, actualMonth);
}
})
.catch(err => {
console.log(`${generateForecastProcedure} exception: `, err);
})
Solution 3:
After analysing 1 hour, I found this. Hope it will be useful to someone
Instead of this request.parameters.SQLReturn you can use recordsets.output.SQLReturn
request.output("SQLReturn");
request.execute('sample', function (err, recordsets, returnValue, results) {
res.json({ code: 1, message: recordsets.output.SQLReturn });
}
Post a Comment for "How To Access The Output Parameter In Node Mssql?"