# Using a named query in a query tag

**URL:** <https://forum.inductiveautomation.com/t/using-a-named-query-in-a-query-tag/57997>\
**Category:** Ignition\
**Created:** [April 4, 2022, 2:48pm UTC](https://forum.inductiveautomation.com/t/using-a-named-query-in-a-query-tag/57997 "2022-04-04T14:48:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwhite](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bwhite/32/7112_2.png) [@bwhite](https://forum.inductiveautomation.com/u/bwhite)\
**Post date:** [April 4, 2022, 2:48pm UTC](https://forum.inductiveautomation.com/t/using-a-named-query-in-a-query-tag/57997/1 "2022-04-04T14:48:38Z")

</div>

Is there any way to use a named query in query tag. I am required to use named queries, and I need to save the query values to a tag after I run the named query. I was planning to use a query tag, but I don’t see a way to use a named query in a query tag.

---

<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:** [April 4, 2022, 2:54pm UTC](https://forum.inductiveautomation.com/t/using-a-named-query-in-a-query-tag/57997/2 "2022-04-04T14:54:06Z")

</div>

There is no direct way to have a query tag use a named query. The reason is because named queries are a project resource, and tags are outside of a project scope.

You’ll have to come up with another way to accomplish this.

What triggers the named query to run? Is it a scalar query or returning multiple values?

---

<div class="post-metadata">

**Author:** ![bwhite](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bwhite/32/7112_2.png) [@bwhite](https://forum.inductiveautomation.com/u/bwhite)\
**Post date:** [April 4, 2022, 3:05pm UTC](https://forum.inductiveautomation.com/t/using-a-named-query-in-a-query-tag/57997/3 "2022-04-04T15:05:46Z")

</div>

We will have the operator push a button. We may also have a script that runs every minute.

---

<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:** [April 4, 2022, 5:11pm UTC](https://forum.inductiveautomation.com/t/using-a-named-query-in-a-query-tag/57997/4 "2022-04-04T17:11:28Z")

</div>

I would suggest that you use either a Gateway Tag Change Event, or a Gateway Timer Event, to run the script. Then you can use `system.db.runNamedQuery()` to run the named query, process the results, whatever they may be, and write the value(s) to tags as appropriate.

---

<div class="post-metadata">

**Author:** ![bwhite](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bwhite/32/7112_2.png) [@bwhite](https://forum.inductiveautomation.com/u/bwhite)\
**Post date:** [April 4, 2022, 5:23pm UTC](https://forum.inductiveautomation.com/t/using-a-named-query-in-a-query-tag/57997/5 "2022-04-04T17:23:26Z")

</div>

I ended up using a button on the view to run the named query and append the new data to the existing tag data. Thanks for your help!
