Using JavaScript with Node.JS to post data to a SQL Server database and return query results from the database

When I attempt to pull data from the database I am getting zero results although my parameter is correct.

From my index.js where CustID is a parameter

app.get('/contacts', (req, res) => {
    actions.getConts(req.params.CustID).then((data) => {
        res.json(data[0]);
    })
})

From my operations.js with GetContNT being a stored procedure on the server

async function getConts(CustID) {
    try {
        let pool = await sql.connect(db);

        let contList = await pool.request()
            .input('CustID', sql.NVarChar, CustID)
            .execute('GetContNT');
        return contList.recordsets;
    }
    catch (error) {
        console.log(error);
    }
}

module.exports = {
    getConts: getConts,
}

If I run the stored procedure by itself on the SQL Server I get results.

If I replace the parameter with the text value, I get results.

With the parameter I get [] … no results

I tried replacing the procedure call .execute('GetContNT'); directly with a query

.query("SELECT * FROM Contacts WHERE CustID = @CustID");

but got the same results.

Appreciate your help.

Read more here: Source link