We have answer of your question!

100% solved queries, no empty question

Question: How to pass an array into mssql query string?


0

Advertisement


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}
Question author Brian-j | Source

Answer


1


Advertisement


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

Source

Answer author Mox

Advertisement


Tickanswer.com is providing the only single recommended solution of the question How to pass an array into mssql query string? under the categories i.e javascript , sql-server , express , . Our team of experts filter the best solution for you.

Related Search Queries:

pass array to sql server stored procedure , pass array to stored procedure in mysql , pass array to stored procedure oracle , pass array in sql query ,

You may also add your answer!