Reputation: 588
I'm using mssql(node.js). I want to execute SQL having LIKE.
But I can't find out in below page https://www.npmjs.com/package/mssql#input-name-type-value
my code is this.But it doesn't work(result is 0 record)
mssql.connect(config, function(err) {
var request = new mssql.Request();
request.input('name',mssql.NVarChar,name);
request.query("SELECT * FROM Table WHERE name LIKE '%@name%',function(err,data){
//
}
Upvotes: 0
Views: 3080
Reputation: 2391
You can use prepared statement like "select * from t where '%' + @param + '%'"
.
For example:
mssql.connect(config, function(err) {
var request = new mssql.Request();
request.input('name', mssql.NVarChar,name);
request.query("SELECT * FROM Table WHERE name LIKE '%' + @name + '%'", function(err,data){
//
}
Upvotes: 2
Reputation: 521168
Try representing the entire LIKE
expression with a parameter, and then bind it using a concatenation, e.g.
var name = 'Yoshihide Nishimoto';
request.query("SELECT * FROM Table WHERE name LIKE ?", '%' + name + '%',
function(err, data) {
// code here
}
)
Upvotes: 1