I have a NodeJS application and I'm trying to insert into a table on a mssql db using the node-mssql package.
I stumbled across the following behaviour when building the sql statement with the data to be inserted provided as an object.
const request = conn.request();
return request.query`INSERT INTO sometable (${Object.keys(data).join(',')}) VALUES (${Object.values(data)});`;
This approach leads to the following error Invalid column name '@param1'.
However, when doing this...:
const request = conn.request();
const query = `INSERT INTO sometable (${Object.keys(data).join(',')}) VALUES (${Object.values(data)});`;
return request.query(query);
...it works as expected and I have no idea what the difference is.
If anyone has an explanation I'd be glad to hear it.