1

so i have this req -

app.delete("/delete/:sku", (req, res) => {
const sku = req.params.sku;
db.query(DELETE FROM products WHERE sku IN(?)

the console.log(req.params.sku) results in - wefwefwef,erferferfrgrwb,23r23r on the console,

i need to convert the sku string to a SQL list so i can insert the values for the IN clause.

2
  • Does this answer your question? NodeJS MSSQL WHERE IN Prepared SQL Statement Commented Sep 30, 2022 at 16:33
  • Ty for the help i found the answer! Commented Oct 1, 2022 at 12:38

1 Answer 1

0

You should use a parameterized query. This could look something like this.

const sku = req.params.sku.split(',');
const ins = new Array(sku.length).fill('?').join();
db.query(`DELETE FROM products WHERE sku IN (${ins})`, sku);

If you need to give the params names like @p1, then something like this

const sku = req.params.sku.split(',');
const ins = sku.map((_, i) => `@p${i}`).join();
db.query(`DELETE FROM products WHERE sku IN (${ins})`, sku);
Sign up to request clarification or add additional context in comments.

1 Comment

Aw man it worked you are a blessing, ty for helping!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.