cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass List of values from json object to SQL Query Service

SOLVED
Highlighted
Regular Member

How to pass List of values from json object to SQL Query Service

I need to call a SQL Query service. Which Look-Likes :

select * from public.styleassociation where id in (?); 

As input I am passing Json Object (Ex:  {  "values" :  [1,2,3]}

Can anyone help me, how to extract the values in "?" place.

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to pass List of values from json object to SQL Query Service

Hello @slangley ,

 

I have found answers my self, the solution is 

we need to iterate the List of values  and append each value as a single string with the single quotes and comas (EX: ‘ID1’,’ID2’). The same string we need to pass as a SQL service parameter and it working fine.

The same approached I have tried with the NUMBER parameter and its working.

 

Ex Code :

var res = "";

for(var i=0; i<tagsArr.length;i++){
var res1 = "\'" + tagsArr[i] + "\'" + ",";
res += res1;
}

var tagsVal = res.substr(0, res.length-1); 

 

And in query param you need to pass  where tag_id IN (<<tagsVal>>) not in [[tagsVal]]

 

Best Regards,

Noor

3 REPLIES 3

Re: How to pass List of values from json object to SQL Query Service

use JSON.parse() method to parse the values before passing it to query

Re: How to pass List of values from json object to SQL Query Service

Hi @snoor.

 

If the solution provided by @rosharma answered your question, please mark it as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

Re: How to pass List of values from json object to SQL Query Service

Hello @slangley ,

 

I have found answers my self, the solution is 

we need to iterate the List of values  and append each value as a single string with the single quotes and comas (EX: ‘ID1’,’ID2’). The same string we need to pass as a SQL service parameter and it working fine.

The same approached I have tried with the NUMBER parameter and its working.

 

Ex Code :

var res = "";

for(var i=0; i<tagsArr.length;i++){
var res1 = "\'" + tagsArr[i] + "\'" + ",";
res += res1;
}

var tagsVal = res.substr(0, res.length-1); 

 

And in query param you need to pass  where tag_id IN (<<tagsVal>>) not in [[tagsVal]]

 

Best Regards,

Noor