提问人:brianw921 提问时间:11/8/2023 最后编辑:Bill Karwinbrianw921 更新时间:11/8/2023 访问量:56
使用连接字符串访问 sql 查询中的返回值
Accessing a return value within a sql query using connection string
问:
我正在使用 mssqlnodev8 连接字符串连接到数据库,但无法访问进行查询的代码块之外的结果。有没有办法让我在查询之外返回我喜欢的值?这是一个辅助函数,我用它来使用数据库将一个值转换为另一个值。
const transformTable = async (field, value) => {
try {
field = field.replace("'","''");
if (typeof value !== 'boolean' ){
value = value.replace("'","''");
}
const query = `SELECT XXX FROM XXXTable WHERE fieldName = '${field}' AND adpName = '${value}'`;
//set the variable that I want to return with this function
let test = '';
//This is where I make the connection using a connection string
await sql.query(connectionString, query, (err, info) => {
if (err){
console.log(err)
return
}
//I want to set the INFO to the test variable that I created outside of this block
test = info
})
//I want to return the value of the variable that I set from info
console.log(test, 'test info')
} catch (error){
console.log(error)
}
}```
答: 暂无答案
评论
SELECT @@version;