IN clause array parameter
See original GitHub issueHi,
Is it possible to give a array as a parameter. for example in a IN clause?
For example:
var query = "SELECT * FROM myTable WHERE code IN (@datas)"
var params = [
{
name: 'datas',
type: sql.VarChar,
value: ['095578','095602']
}
];
async.waterfall([
function (callback) {
createConnection(callback);
},
function (connection, callback) {
var request = connection.request();
params.forEach(function (param) {
request.input(param.name, param.type, param.value);
});
request.query(query, function (err, recordset) {
if (err) {
callback(err, null);
}
else {
callback(null, recordset);
}
});
}
], function (err, recordset) {
if (err) {
next(err, null);
}
else {
next(null, recordset);
}
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:12
Top Results From Across the Web
Passing an array as a parameter in a WHERE IN clause
I am trying pass in an array of strings (internal_id) to a query. The portion below counts how many elements are in the...
Read more >Parameterised query Problem with IN clause when passing ...
In my SQL query there is IN condition in where clause and the array of string values are used in IN condition. The...
Read more >How to pass int array in SQL parameterized query to in clause ...
I have an SQL query that uses string format to insert the int array(pubIds) into the query argument which is set to CommandText...
Read more >Use a query parameter as a list in an IN clause - Google Support
UNNEST takes an ARRAY and returns a table with a single row for each element in the ARRAY . OR: SELECT [ 1234,5678,9012,3456,7890...
Read more >Getting error while passing array parameters to select statement
It is not correct for array. Your SQL uses array of employee and array of batchid - 2 arrays. Your input has one...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For now, I’ve created a function which adds parameters dynamically like below. It is SQL Injection safe and can work for any type (no need to worry about quotes) as I’ve taken type as an argument.
Function:
Usage:
I still wish if something like below should support, so programmers don’t have to all this and also don’t have to worry about sanitization to prevent injection.
Thanks,
I know it’s too late but for anyone else that’s looking for the solution to this problem you can use this
and provided as a comma-separated string