tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.23k stars 466 forks source link

IN clause parametrize issue #1602

Closed CT77777 closed 8 months ago

CT77777 commented 8 months ago
    const request = pool.request()

    const param = {
      name: 'coids',
      type: sql.VarChar,
      value: ['000020', '000024'],
    }

    request.input(param.name, param.type, param.value)

    const query = 'SELECT coid, fin_type FROM wifina WHERE coid IN (@coids)'

     const result = await request.query(query)

    await pool.close()

    return result.recordset

show below error

RequestError: Validation failed for parameter 'coids'. Invalid string.

then I covert param.value to string, it return empty array.

dhensby commented 8 months ago

You can't parameterise arrays into single values.

Somewhat releated: https://github.com/tediousjs/node-mssql/issues/1575