# Insert tag into a tag query where clause?

**URL:** <https://forum.inductiveautomation.com/t/insert-tag-into-a-tag-query-where-clause/69219>\
**Category:** Ignition\
**Created:** [January 31, 2023, 5:02pm UTC](https://forum.inductiveautomation.com/t/insert-tag-into-a-tag-query-where-clause/69219 "2023-01-31T17:02:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [January 31, 2023, 5:02pm UTC](https://forum.inductiveautomation.com/t/insert-tag-into-a-tag-query-where-clause/69219/1 "2023-01-31T17:02:26Z")

</div>

How do I insert a tag into where clause when creating tag query? I insert it but keep getting an expression error?

SELECT SUM(Duration)  
FROM Table  
WHERE Column1 = {[.]Description1} AND Column2 = {[.]Description2} AND WorkingDate = CAST( GETDATE() AS Date )

---

<div class="post-metadata">

**Author:** ![Gurjot\_Sandhu](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gurjot_sandhu/32/38368_2.png) [@Gurjot\_Sandhu](https://forum.inductiveautomation.com/u/Gurjot_Sandhu)\
**Post date:** [February 7, 2023, 10:05pm UTC](https://forum.inductiveautomation.com/t/insert-tag-into-a-tag-query-where-clause/69219/2 "2023-02-07T22:05:10Z")

</div>

Hi [Ly17](https://forum.inductiveautomation.com/u/Ly17),

What version of Ignition are you using? Just to clarify, you are writing this query in a query tag right? Where do you see the error and what exactly does it say?

When you are writing the query, it is suggested you use the Insert Tag button on the right side of that box. Is that what you used?

---

<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 7, 2023, 10:11pm UTC](https://forum.inductiveautomation.com/t/insert-tag-into-a-tag-query-where-clause/69219/3 "2023-02-07T22:11:31Z")

</div>

Tag insertion with curly braces performs a string substitution into the SQL without regard for the structure of the query. You will need single quotes enclose any non-numeric substitutions, possibly with manual casting, and may need intermediate tags for character escaping.

Instead of using a query tag, consider using a memory tag, then use a timer script at the same pace to execute your query with one of the scripted forms that handle parameters for you. Write the return value from `system.db.runPrep*()` and/or `system.db.runNamedQuery()` to your memory tag.

---

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [February 17, 2023, 8:56pm UTC](https://forum.inductiveautomation.com/t/insert-tag-into-a-tag-query-where-clause/69219/4 "2023-02-17T20:56:54Z")

</div>

Thanks. That fixed the problem once I included single quotes.

That's an interesting alternative. I'll keep that in mind. Thanks.

---

<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 17, 2023, 9:37pm UTC](https://forum.inductiveautomation.com/t/insert-tag-into-a-tag-query-where-clause/69219/5 "2023-02-17T21:37:04Z")

</div>

Wait until someone puts a single quote in either description tag.

In other words, it isn't just an alternative. It is a substantially more robust approach.
