Can someone tell me what is wrong with this code? I am getting syntax error near Select category_ID; I am using latest version is mysql in nodejs
Note - If i remove the output params, Input code is properly working.
Node Server Code -
app.post('/api/createcategory', function (req, res) {
name = req.body.categoryName, icon = req.body.categoryIcon;
let createcategory = `CALL spAddCategory(?, ?, @category_id); SELECT @category_id;`
db.query(createcategory, [name, icon], (err, result) => {
if(err) {throw err};
console.log(result);
})
res.send('Category Created')
})
SQL Query -
CREATE PROCEDURE spAddCategory ( IN category_name varchar(255), IN category_icon varchar(255), OUT category_id int )
BEGIN
INSERT INTO categories ( categoryName, categoryIcon )
VALUES ( category_name, category_icon );
SELECT categoryID INTO category_id FROM categories
WHERE categoryName = category_name;
END