gpt4 book ai didi

javascript - Node : How to use LIKE with an input parameter in the query? 的 MSSQL

转载 作者:行者123 更新时间:2023-11-30 14:46:26 25 4
gpt4 key购买 nike

我不知道如何提出问题,也找不到解决方案。我正在使用 mssql NPM 包。文档对此没有任何内容。

我想让它工作:

SELECT product_price
FROM products
WHERE product_name LIKE '%SEARCH_CRITERIA%' -- note the '%%' part

使用 Node 的 mssql npm 包:

var query = `
SELECT product_price
FROM products
WHERE product_name LIKE @input_parameter
`

new sql.ConnectionPool(db).connect().then(pool => {
return pool.request()
.input('input_parameter', criteria) // How do I make LIKE work?
.query(query)
}).then(result => {
res.send(result)
}).catch(err => {
res.status(500).send({ message: "${err}"})
sql.close();
});

在查询中使用 = 可以正常工作,但我需要 LIKE 一个。

最佳答案

您是否尝试过使用 % 作为 criteria 内容的前缀和后缀?

例如

new sql.ConnectionPool(db).connect().then(pool => {
return pool.request()
.input('input_parameter', '%'+criteria+'%')
.query(query)
}).then(result =>
...etc

关于javascript - Node : How to use LIKE with an input parameter in the query? 的 MSSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48845291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com