0

I'm using the mssql node package to perform queries on a SQL Server DB. Now I want to pass in an array of intergers to the query string. So I grab The array from req.query.rids and the values output are as follows:

var RIDS = JSON.parse(req.query.rids);
logger.info(`${RIDS}`)  // result shows: 204294,204303,104354

But when I use the IN operator to check for a match to any of the array values. I get the error error: Incorrect syntax near '204294'. What I understand from this is that the RID array being passed in is not in the correct format for the query.

Question:

How do I pass in an array into mssql query string? `

This is a snippet of the query where I check for a match in the RIDS array:

Left Join [Metrics_DB].[dbo].[AssetBundle]
  on [Metrics_DB].[dbo].[Assetdata].RID=[Metrics_DB].[dbo].[AssetBundle].[RID]
   where [Asset Sunset Date] is not null and [OSM_Metrics_DB].[dbo].[Assetdata].RID IN ${RIDS}
1
  • WHERE ... IN (value1, value2, value3, value3, ...) - Exploits of a mom Commented Jan 10, 2017 at 11:34

1 Answer 1

1

You need to stringify and format your array in the style of (item, item, item).

Source

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.