# Multi-select dropdown to MSSQL table

**URL:** <https://forum.inductiveautomation.com/t/multi-select-dropdown-to-mssql-table/79286>\
**Category:** Ignition\
**Tags:** ignition81, perspective, database\
**Created:** [September 18, 2023, 1:26pm UTC](https://forum.inductiveautomation.com/t/multi-select-dropdown-to-mssql-table/79286 "2023-09-18T13:26:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [September 18, 2023, 1:26pm UTC](https://forum.inductiveautomation.com/t/multi-select-dropdown-to-mssql-table/79286/1 "2023-09-18T13:26:52Z")

</div>

I'm trying to figure out how to break down the multiple selections in a dropdown and insert them into a table.

The project is for users to report observations. I have 3 tables, first is for the report details, second is for the list of items they can pick. (they can pick none, one, or many items from the list) and the third will store those items with the two keys from table 1 and 2.

So if observation\_ID 1 has 2 items (A&C) then table 3 would have 2 rows. 1 | A, 1 | C.

I can't find any documentation or posts on how to break apart the selections from the dropdown an insert them into the table.

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 18, 2023, 2:43pm UTC](https://forum.inductiveautomation.com/t/multi-select-dropdown-to-mssql-table/79286/2 "2023-09-18T14:43:22Z")

</div>

When multi-select is enabled, the `value` prop of the dropdown will be a list.  
You just need to grab everything in that list.

something like that:

```python
from itertools import chain

obs_id = obs_dropdown.value
item_values = item_dropdown.value

marks = ','.join("(?, ?)" for _ in item_values)
query = """
insert into your_table (obs_id, item_id)
values {}
""".format(marks)

values = list(chain.from_iterable((obs_id, item_id) for item_id in item_values))

system.db.runPrepUpdate(query, values)

```

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [September 18, 2023, 4:25pm UTC](https://forum.inductiveautomation.com/t/multi-select-dropdown-to-mssql-table/79286/3 "2023-09-18T16:25:57Z")

</div>

Thank you!

I'm assuming obs\_id is the record value from the first table.

One question. Where are you getting the item\_id from?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 18, 2023, 4:35pm UTC](https://forum.inductiveautomation.com/t/multi-select-dropdown-to-mssql-table/79286/4 "2023-09-18T16:35:35Z")

</div>

obs\_id is found in the `value` parameter of the first dropdown,  
item\_id comes from the `value` parameter of the second dropdown.  
It's extracted in a comprehension:

```python
... for item_id in item_values

```

which is equivalent to

```python
for item_id in item_values:
    ...

```

Here, I used a generator expression to generate tuples containing the obs\_id and each item\_id:

```python
(obs_id, item_id) for item_id in item_values

```

Then used `chain.from_iterable` to "flatten" the list of tuples into a simple 1d list, which can be passed as values to `runPrepQuery`

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [September 18, 2023, 7:40pm UTC](https://forum.inductiveautomation.com/t/multi-select-dropdown-to-mssql-table/79286/5 "2023-09-18T19:40:40Z")

</div>

Thank you once again, you're awesome!
