Passing selected table values to a SQL IN statement

Hi,

Having an issue with a SQL select statement, when trying to pass a list of values from a Javascript transformer. If I select only 1 row in a table, the query works perfectly.

However, if I try selecting more than 1 value, I get the following error:

  • message:"Conversion failed when converting the nvarchar value '169497,336273' to data type int."

Javascript transformer:

function selectStockItemIDs() {
const selectStockItemIDs = table1.selectedRows.map(row => '${row.g_STOCKITEMID}').join(', ');
return selectStockItemIDs;
}

return selectStockItemIDs();

maybe the transformer is returning ["value", "value"] (array) and i think IN expects items separated by commas and not arrays

Hi there! This post has some helpful examples for working with arrays in Retool SQL queries :slightly_smiling_face:

Let us know if the MS SQL examples don't work for your db