# Make dynamic report query with table name

**URL:** <https://forum.inductiveautomation.com/t/make-dynamic-report-query-with-table-name/91337>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [June 4, 2024, 12:08pm UTC](https://forum.inductiveautomation.com/t/make-dynamic-report-query-with-table-name/91337 "2024-06-04T12:08:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samer\_samy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/samer_samy/32/52910_2.png) [@samer\_samy](https://forum.inductiveautomation.com/u/samer_samy)\
**Post date:** [June 4, 2024, 12:08pm UTC](https://forum.inductiveautomation.com/t/make-dynamic-report-query-with-table-name/91337/1 "2024-06-04T12:08:01Z")

</div>

Dears,  
I have tens of circuit breakers tables ,I want to build a report viewer that shows the data depending on a chosen CB from a drop down list.

I tried to make a report query with dynamic table name but it is showing an error and can not procced.

Any advices?

Regards,

 ![11](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/b/6bf2e72a80a439c454e82ff3c3dce5ea3b5b630d.png)  
 ![22](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/d/4df3aff53f507da179b997a1d5db68c15fd1130c.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:** [June 4, 2024, 12:16pm UTC](https://forum.inductiveautomation.com/t/make-dynamic-report-query-with-table-name/91337/2 "2024-06-04T12:16:22Z")

</div>

Question mark substitutions can only provide **values** to queries, not structural items like table or column names.

If all the tables have the same structure, why do you not have a single table with an indexed column to show what machine a particular row belongs to? Then you can put that (as a value substitution) in a WHERE clause.

---

<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:** [June 4, 2024, 12:33pm UTC](https://forum.inductiveautomation.com/t/make-dynamic-report-query-with-table-name/91337/3 "2024-06-04T12:33:20Z")

</div>

Crop the images, man! Crop the images! 80% of them is empty. At least resize them. You can also use tools like Snagit (paid) or [https://greenshot.org](https://greenshot.org) (open source) to do nice stuff. They're both for Windows but other flavours will be available.

 ![Crop demo](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/a/8ad4328b7a6f02c1fa8b4d0ede407800e0a509cf.png)

---

<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:** [June 4, 2024, 4:59pm UTC](https://forum.inductiveautomation.com/t/make-dynamic-report-query-with-table-name/91337/4 "2024-06-04T16:59:52Z")

</div>

While, @pturmel's response is definitely the preferred and best practice. Should you be in a position where you can not modify the DB. Then the best way to accomplish your goal would be to use a script data source with `system.db.runPrepQuery()` where you build the query string dynamically inserting the needed table name.

---

<div class="post-metadata">

**Author:** ![samer\_samy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/samer_samy/32/52910_2.png) [@samer\_samy](https://forum.inductiveautomation.com/u/samer_samy)\
**Post date:** [June 6, 2024, 12:26pm UTC](https://forum.inductiveautomation.com/t/make-dynamic-report-query-with-table-name/91337/5 "2024-06-06T12:26:27Z")

</div>

Thanks @pturmel ,I think my power management system is completed now 🕶

 ![Screenshot 2024-06-06 152222](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/d/2d920344e89d8f753e8ad62994acb5da4f88c640.png)
