2
`  request.input('xyz',sql.Int,1);
    request.input('abc',sql.Numeric,2);
    request.output('pqr',sql.Int);
    request.output('def',sql.Char);
      request.execute('[StoredProcedure]',function(err,recordsets,returnvalue){
      next.ifError(err);
      console.log(returnvalue);
    })`

Now the problem is how will i access the output parameters.

Regards.

Prateek Dhuper
  • 235
  • 4
  • 14

3 Answers3

13

request.parameters.pqr.value and request.parameters.def.value

Got the answer , so sharing it :)

Prateek Dhuper
  • 235
  • 4
  • 14
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);
        })
gil.fernandes
  • 12,978
  • 5
  • 63
  • 76
0

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 });
                }
KCN
  • 472
  • 6
  • 19