# Ignition Perspective Named Query with WHERE IN Clause

**URL:** <https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062>\
**Category:** Ignition\
**Created:** [April 21, 2020, 1:33am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062 "2020-04-21T01:33:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![David.Bell](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@David.Bell](https://forum.inductiveautomation.com/u/David.Bell)\
**Post date:** [April 21, 2020, 1:33am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/1 "2020-04-21T01:33:43Z")

</div>

Hello, I need to create a Named Query using WHERE IN a multiple selection on a form. Can this be done?

Thanks in advance

 ![20Apr20_WhereInClause](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d234297c6a29c980cd87b84f2111ca8dd2927bed.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 21, 2020, 1:51am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/2 "2020-04-21T01:51:36Z")

</div>

You’ll have to use a parameter of type “QueryString” and supply the properly formatted segment of the query in a string. Instead of using the colon prefix to the parameter, use curly braces around the parameter name.

---

<div class="post-metadata">

**Author:** ![David.Bell](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@David.Bell](https://forum.inductiveautomation.com/u/David.Bell)\
**Post date:** [April 21, 2020, 2:29am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/3 "2020-04-21T02:29:31Z")

</div>

Thank you for your quick response. I saw an example.of that earlier, but when I tried it I was unable to get it to work. When I made my 2nd parameter a query string I got the yellow triangle. Then when I tried to execute the query I got an error message. Do you have a good example you can send me? I will try again.  
Maybe, I just missed something.

Thanks.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 21, 2020, 11:46am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/4 "2020-04-21T11:46:32Z")

</div>

Have you looked at [the manual](https://docs.inductiveautomation.com/display/DOC80/Named+Query+Parameters#NamedQueryParameters-QueryString)?

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [April 21, 2020, 2:16pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/5 "2020-04-21T14:16:54Z")

</div>

If you turn the logger for `GatewayNamedQueryManager` to debug, you can see how the gateway constructed the query it’s trying to run. That may help you figure out what you’re doing wrong.

---

<div class="post-metadata">

**Author:** ![David.Bell](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@David.Bell](https://forum.inductiveautomation.com/u/David.Bell)\
**Post date:** [April 21, 2020, 2:20pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/6 "2020-04-21T14:20:25Z")

</div>

Thank you both. I just got it working. I used QueryString and then used:

WHERE CAST(Date AS DATE) = CAST( :DateSelected AS DATE) AND Department in ({DeptSelected})

I then had to go to the View and convert my dropdown list where I have multiple items selected to a global session value as ‘1’,‘2’,3’ for example.

Thanks!!

David

---

<div class="post-metadata">

**Author:** ![Killmonger](https://avatars.discourse-cdn.com/v4/letter/k/3da27b/32.png) [@Killmonger](https://forum.inductiveautomation.com/u/Killmonger)\
**Post date:** [September 14, 2022, 5:57am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/7 "2022-09-14T05:57:39Z")

</div>

Hi, @David.Bell can you elaborate on how to convert the dropdown list containing multiple values to a global session value containing selection values separated by commas so as to input the same in the query string parameter?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 14, 2022, 6:17am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/8 "2022-09-14T06:17:16Z")

</div>

This is really a question on a different topic unrelated to this thread. However …  
I think you are asking how to bind a multi-select dropdown ‘value’ to a session variable.

1. In the Project Browser, select _Perspective_.
2. In the Perspective Property Editor | Session Custom, add a new custom property of type Array. Call it `ddSelection` or whatever.
3. On your view, select the dropdown and in the Perspective Property Editor add a property binding on `props.value` to `session.custom.ddSelection` and make it bidirectional.

For debugging purposes add a label to the view, bind it to the session variable, turn on preview and you should see a list of selected values or `[]` when nothing is selected.

---

<div class="post-metadata">

**Author:** ![Killmonger](https://avatars.discourse-cdn.com/v4/letter/k/3da27b/32.png) [@Killmonger](https://forum.inductiveautomation.com/u/Killmonger)\
**Post date:** [September 14, 2022, 6:36am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/9 "2022-09-14T06:36:00Z")

</div>

hi @Transistor, everything works perfectly. As you mentioned, I am getting , when there is no selection, and [A, B] let's say when A and B are selected. But for my named query to work, I need this to be ['A', 'B']. This I am not able to achieve. Can you kindly help me in that regards too..

Thanks

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 14, 2022, 8:25am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/10 "2022-09-14T08:25:02Z")

</div>

![Dropdown to SQL](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/0/605ad6f006636d191c2645ddacbc77c04fe1e732.png)

Try quoting your dropdown values.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 14, 2022, 9:28am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/11 "2022-09-14T09:28:13Z")

</div>

You’ll need to script it as the named query is expecting a string, not an object.

Use a script transform on a property binding to your dd selection:

```auto
return "'" + "','".join({value}) + "'" 

```

This will return your selected values as a string with quotes and comma separated

---

<div class="post-metadata">

**Author:** ![Killmonger](https://avatars.discourse-cdn.com/v4/letter/k/3da27b/32.png) [@Killmonger](https://forum.inductiveautomation.com/u/Killmonger)\
**Post date:** [September 14, 2022, 10:15am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/13 "2022-09-14T10:15:59Z")

</div>

@nminchin this works like a charm. I was tryna achieve the same by converting the array into a string and then using regex on the same. Also many thanks to @Transistor for the other answers.
