# Query Tags: Named Queries

**URL:** <https://forum.inductiveautomation.com/t/query-tags-named-queries/107194>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 9, 2025, 7:59pm UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194 "2025-06-09T19:59:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [June 9, 2025, 7:59pm UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194/1 "2025-06-09T19:59:25Z")

</div>

Can named queries be used inside of query tags?

---

<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 9, 2025, 8:00pm UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194/2 "2025-06-09T20:00:55Z")

</div>

No, unfortunately.

---

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [June 9, 2025, 8:05pm UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194/3 "2025-06-09T20:05:40Z")

</div>

Ok. I tried writing the query in the UDT to reference the Named Query in the example below with a parameter, but it doesn't seem to work.

```python
EXECUTE NAMED QUERY 'MF1_Dashboard', 'shift/GetPreviousShift'
WITH PARAMETERS
	machine_id = {MachineID}

```

Thanks

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [June 9, 2025, 8:20pm UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194/4 "2025-06-09T20:20:27Z")

</div>

Named queries are project scoped, tags are gateway scoped.

> [@Aisha\_Shiddat](#):
>
> `EXECUTE NAMED QUERY`

Isn't a valid SQL statement either. You will need to create the query with the proper select statements that use the parts of the UDT you want to query the SQL Database. See: [Types of Tags | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/platform/tags/types-of-tags#query-tags) for more information about Query Tags.

---

<div class="post-metadata">

**Author:** ![simeonw](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@simeonw](https://forum.inductiveautomation.com/u/simeonw)\
**Post date:** [June 9, 2025, 10:42pm UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194/5 "2025-06-09T22:42:37Z")

</div>

**UPDATED:** I suggested using an expression tag with runScript to execute the named query in a script, but as @pturmel pointed out, not a good idea. Good explanation below.

Always learning.

---

<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 9, 2025, 10:47pm UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194/6 "2025-06-09T22:47:00Z")

</div>

> [@simeonw](#):
>
> execute the named query from an expression tag

Don't do this. Expression tags execute in a small thread pool, separate from but otherwise just like tag events. Any long-running database operation will tie up a thread from this pool. Get three such expressions at once, and _ **ALL** _ expression tags in the system will stall.

Queries that don't fit the very simple model in Query Tags need to be moved to a gateway event (in a project, not a tag event).

---

<div class="post-metadata">

**Author:** ![simeonw](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@simeonw](https://forum.inductiveautomation.com/u/simeonw)\
**Post date:** [June 9, 2025, 11:02pm UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194/7 "2025-06-09T23:02:37Z")

</div>

> [@pturmel](#):
>
> y Tags need to be moved to a gateway event (in a project, not a tag event).

Thanks for pointing this out @pturmel. A great example of what NOT to do then 😅

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [June 9, 2025, 11:17pm UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194/8 "2025-06-09T23:17:27Z")

</div>

If you are bent on using a named query, then just setup a gateway timer event to update your tags.

---

<div class="post-metadata">

**Author:** ![Aisha\_Shiddat](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Aisha\_Shiddat](https://forum.inductiveautomation.com/u/Aisha_Shiddat)\
**Post date:** [June 10, 2025, 9:23am UTC](https://forum.inductiveautomation.com/t/query-tags-named-queries/107194/9 "2025-06-10T09:23:32Z")

</div>

Yes, I just utilized the gateway timerevent  
to update my tags. -Thanks
