SQL Server Statement - How. do you INSERT multiselect output as a string in a column?

with col1:
        with st.form("Submit Form"):
            submit_current_date = current_date
            submit_streamlit_id = st.experimental_user
            submit_origin = st.multiselect(label='Origins (required):', options=list_of_origins)
            submit_form = st.form_submit_button(label='Submit Form')
            if submit_form:
                session.sql(f"""INSERT INTO DATABASE.SCHEMA.TABLE (SUBMISSION_DATE, STREAMLIT_ID, ORIGIN) VALUES ('{submit_current_date}', '{submit_streamlit_id}','{submit_origin}')""").collect()
                st.success('Success!', icon="✅")

ERROR MESSAGE: SnowparkSQLException: (1304): 01aef77a-0508-4047-0000-380945e4ae0e: 001003 (42000): SQL compilation error: syntax error line 1 at position 412

Print the SQL to see what is wrong with it.

See also the story of Bobby Tables.

Hi @Todd_Steussie ,

submit_origin is a multi-select, therefore, will return a list instead of a string, which could be playing into the error, if you only need 1 value, use a selectbox instead.

Unfortunately I need to allow users to provide multiple values. I figured a work around, by converting the list into a string, it can then be included in an INSERT statement.
submit_origins_str = ', '.join(submit_origins)


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.