Need help with the following issue related to loops in sql?

I have a sql procedure which requires the following 3 values as input:
@sku varchar(10) = {{skus}}
@date varchar(10) = {{dates}}
@col_value varchar(10) = {{col_values}}

In Retool,
#1: SKUs come from a Multiselect components:
Example: Say These are skus: AB , BC and CD selected in the multiselect
Answer: @sku varchar(10) = sku_fetched IN ( SELECT convert(varchar, value) FROM string_split({{ slctItems.value }}, ',') )

is the above correct?

#2:There is a Legacy Table called LegacyTable whose column name contains dates, so we only fetch those column names here:
So, I used the transformer along with help from here: How to get only specific table columns? - #5 by dcartlidge
return _.pull( {{ _.values(tableLegacy5.columns) }}, "Account_ID","Product_ID","Bulk_Update" );

The above transformer returned required column names.
Answer: @date varchar(10) = dates IN ( SELECT convert(varchar, value) FROM string_split({{transformer.value}}, ',') )

is the above correct?

#3: From the same LegacyTable @col_value denotes the value of each of the column names in #2:

For example: Column name is: 2023-04-23 and its value is 0

Then how to correctly fetch and pass these values and they are editable in table?

In the end I'm updating them in the db.

Do I need specific loops for the query for processing something like this: @sku varchar(10) = sku_fetched IN ( SELECT convert(varchar, value) FROM string_split({{ slctItems.value }}, ',') )

or it is auto handled?

Tagging all the pros for better reach: @victoria @ScottR @dcartlidge @Tess @kbn @Kabirdas

Hey @khatanaashish!

This post might help you with using the Multiselect component's array value in a SQL query:

Also, let me know if it sounds like you're running into a Prepared Statements issue:

For your last question, it sounds like you need to change your column names before updating from Retool to match the column names in your database? If so, maybe something like this?

FWIW, the new Table component shouldn't have this issue since you can set column ids vs labels, but I assume you have valid reasons for using the legacy Table!

Let me know if you have any questions :slight_smile: