# Report Query- Table name as parameter (7.9)

**URL:** <https://forum.inductiveautomation.com/t/report-query-table-name-as-parameter-7-9/43569>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [February 18, 2021, 3:23pm UTC](https://forum.inductiveautomation.com/t/report-query-table-name-as-parameter-7-9/43569 "2021-02-18T15:23:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Troy](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Troy](https://forum.inductiveautomation.com/u/Troy)\
**Post date:** [February 18, 2021, 3:23pm UTC](https://forum.inductiveautomation.com/t/report-query-table-name-as-parameter-7-9/43569/1 "2021-02-18T15:23:57Z")

</div>

In the Reporting Module, I have a script that determines which table the data is in, then sets data[‘db\_table’] = ‘myTable’.

Then the query runs after the script, but gives an error saying “@p0” is not defined, even if I give it a default value. The xml also shows the correct table name in the preview.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 18, 2021, 3:29pm UTC](https://forum.inductiveautomation.com/t/report-query-table-name-as-parameter-7-9/43569/2 "2021-02-18T15:29:51Z")

</div>

SQL will not accept schema as a parameters, so I doubt you would be able to make this work with a standard query. Assuming that I am understanding what you have in your query.

---

<div class="post-metadata">

**Author:** ![Troy](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Troy](https://forum.inductiveautomation.com/u/Troy)\
**Post date:** [February 18, 2021, 3:50pm UTC](https://forum.inductiveautomation.com/t/report-query-table-name-as-parameter-7-9/43569/3 "2021-02-18T15:50:26Z")

</div>

SELECT \* FROM ?  
WHERE t\_stamp \>= ? AND t\_stamp \<= ?

I am querying transaction groups, there are 4 tables, one for each “system” in the warehouse.

---

<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 18, 2021, 3:57pm UTC](https://forum.inductiveautomation.com/t/report-query-table-name-as-parameter-7-9/43569/4 "2021-02-18T15:57:39Z")

</div>

You can’t use ‘?’ substitution for table names, column names, etc. Those are schema identifiers. You have to use string substitution. In a named query, this would be a parameter of type “QueryString” instead of type “Value”.

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

Be aware that using strings for schema may be allowed, but it is a potential security hole. Don’t supply user-supplied strings to QueryString parameters.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 18, 2021, 4:07pm UTC](https://forum.inductiveautomation.com/t/report-query-table-name-as-parameter-7-9/43569/5 "2021-02-18T16:07:34Z")

</div>

> [@pturmel](#):
>
> You have to use string substitution. In a named query, this would be a parameter of type “QueryString” instead of type “Value”.
> 
> [Named Query Parameters - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Named+Query+Parameters)

Since you flagged this as 7.9, you may or may not have access to named queries.

You can also accomplish this within a script data source.

Here is a decent thread that covers a similar issue:

> [@Passing different datatypes tp a named query](http://forum.inductiveautomation.com/t/passing-different-datatypes-tp-a-named-query/40067/22):
>
> And if you want to do both the table name and the column name then you could do something like this: tableName ="binder\_names" columnName = "binder\_name" query = "UPDATE {0} SET {1}=? WHERE id=?".format(tableName,columnName) system.db.runPrepUpdate(query=query, args=args)

---

<div class="post-metadata">

**Author:** ![Troy](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Troy](https://forum.inductiveautomation.com/u/Troy)\
**Post date:** [February 18, 2021, 4:08pm UTC](https://forum.inductiveautomation.com/t/report-query-table-name-as-parameter-7-9/43569/6 "2021-02-18T16:08:52Z")

</div>

We are using 7.9.3, so I do not have named queries

---

<div class="post-metadata">

**Author:** ![Troy](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Troy](https://forum.inductiveautomation.com/u/Troy)\
**Post date:** [February 18, 2021, 4:15pm UTC](https://forum.inductiveautomation.com/t/report-query-table-name-as-parameter-7-9/43569/7 "2021-02-18T16:15:44Z")

</div>

That worked. Thank you
