# How to pass a table name parameter to named query?

**URL:** <https://forum.inductiveautomation.com/t/how-to-pass-a-table-name-parameter-to-named-query/32689>\
**Category:** Ignition\
**Created:** [February 28, 2020, 4:24am UTC](https://forum.inductiveautomation.com/t/how-to-pass-a-table-name-parameter-to-named-query/32689 "2020-02-28T04:24:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [February 28, 2020, 4:24am UTC](https://forum.inductiveautomation.com/t/how-to-pass-a-table-name-parameter-to-named-query/32689/1 "2020-02-28T04:24:52Z")

</div>

I am trying to pass in the name of a table to a named query, If I hard code the table name in the query it works, but when I pass in the name as a parameter I get a syntax error. Any ideas?

 ![ig_namedquery_tablepar_01](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/1be26b3b8ed945263c08fddc36f872bd7e8049b4.jpeg)  
 ![ig_namedquery_tablepar_02](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/ee315ebc849be8d7a19527455323d5adc47965fd.jpeg)

---

<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:** [February 28, 2020, 12:20pm UTC](https://forum.inductiveautomation.com/t/how-to-pass-a-table-name-parameter-to-named-query/32689/2 "2020-02-28T12:20:27Z")

</div>

Change the type of the parameter from Value to QueryString, and use curly braces around it in the SQL. Per the manual:

[https://docs.inductiveautomation.com/display/DOC80/Named+Query+Parameters](https://docs.inductiveautomation.com/display/DOC80/Named+Query+Parameters)

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [February 28, 2020, 3:36pm UTC](https://forum.inductiveautomation.com/t/how-to-pass-a-table-name-parameter-to-named-query/32689/3 "2020-02-28T15:36:09Z")

</div>

That fixed the query,

 ![ig_namedquery_tablepar_03](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/01b3fb84f2f4e9f852105158a7abe852b101ed9f.jpeg)

but when I apply it in a table component binding I get a configuration error:

 ![ig_namedquery_tablepar_04](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/1922b8a385b7450d45f7d1e3514bc215f840ea45.jpeg)

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [February 28, 2020, 4:17pm UTC](https://forum.inductiveautomation.com/t/how-to-pass-a-table-name-parameter-to-named-query/32689/4 "2020-02-28T16:17:24Z")

</div>

I found that unlike the named query test, when I use it in a binding I need single quotes (‘List’). Now I have to figure out how to put those into a dynamic value reference

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 28, 2020, 4:26pm UTC](https://forum.inductiveautomation.com/t/how-to-pass-a-table-name-parameter-to-named-query/32689/5 "2020-02-28T16:26:10Z")

</div>

~~When using a query string parameter, whatever parameter you supply will be inserted _verbatim_ into the executed query. So if you’re using an expression to reference `someTable`, it’ll go into your query as:~~

```sql
SELECT * 
FROM someTable

```

~~You can just add the quotes in your named query, since, again, it’s a literal string replacement, _not_ the parameter substitution that’s preferred for named queries (_because_ it’s a literal string replacement, it re-opens the SQL injection vulnerability named queries were designed to prevent). So:~~

```sql
SELECT *
FROM '{TableList}'

```

~~Should work just as well.~~

EDIT: Nope, Phil and Oscar are right, ignore me.

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [February 28, 2020, 4:35pm UTC](https://forum.inductiveautomation.com/t/how-to-pass-a-table-name-parameter-to-named-query/32689/6 "2020-02-28T16:35:30Z")

</div>

The reason you needed single quotes in the binding is because when you set values in there the input is actually an [expression editor](https://docs.inductiveautomation.com/display/DOC80/Expression+Overview+and+Syntax) which expects string literals to be in quotes. This allows you to dynamically assign values in bindings. You’d see more of the editor if you hit the little “fx” button on the right of the cell.

---

<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:** [February 28, 2020, 5:14pm UTC](https://forum.inductiveautomation.com/t/how-to-pass-a-table-name-parameter-to-named-query/32689/7 "2020-02-28T17:14:18Z")

</div>

> [@paul-griffith](#):
>
> opens the SQL injection vulnerability named queries were designed to prevent). So:
> 
> ```auto
> SELECT *
> FROM '{TableList}'
> 
> ```
> 
> Should work just as well.

Uhm, no. Single quotes in SQL are always value quotes, never identifier quotes. But see @osolorzano's comment for why single quotes work in this case (they aren't injected into the SQL).
