I am using the mssql package in my Node project to handle querying for data in my SQL Server db. I am running into a challenge with this particular query:
const idArr = ['A123', 'B456'];
SELECT DOCNO
FROM dbo.SA30301
WHERE DOCNO
IN (${idArr})
The problem is that, with this syntax, the values will not be passed in as strings, even though the array contains string values. So with this implementation I get an invalid column name error.
I've also tried this:
SELECT DOCNO
FROM dbo.SA30301
WHERE DOCNO
IN ('${idArr}')
... and while this doesn't error out, it doesn't return any records because basically both values are passed in as one long string.
Also, FYI, the type for DOCNO in SQL Server is char(17).
So my question is, how can I make sure these values get evaluated as individual string values?
My other option may be to use a for-loop and go one by one, but that will result in many hits to the db rather than just one.