# Query tag parameter UDT

**URL:** <https://forum.inductiveautomation.com/t/query-tag-parameter-udt/111908>\
**Category:** Ignition\
**Created:** [November 3, 2025, 6:27pm UTC](https://forum.inductiveautomation.com/t/query-tag-parameter-udt/111908 "2025-11-03T18:27:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luis\_Martin](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@Luis\_Martin](https://forum.inductiveautomation.com/u/Luis_Martin)\
**Post date:** [November 3, 2025, 6:27pm UTC](https://forum.inductiveautomation.com/t/query-tag-parameter-udt/111908/1 "2025-11-03T18:27:25Z")

</div>

Hi everyone,

I have a **Query Tag** inside a **UDT** that reads data from SQL Server.  
The query works fine when I use a fixed table name, but it fails when I pass the table name as a UDT parameter.

Example:

```python
SELECT TOP(1)
    kgtotalizador
FROM
    {BASCULA}
WHERE
    fechainsert > CONVERT(datetime, '{[.]../../GLOBAL/FechaHoraDia}', 120)
ORDER BY
    id ASC

```

If I replace `{BASCULA}` with the actual table name (for example `T1`), the query works perfectly.  
If I remove the `WHERE` clause, it also works fine.

So the issue only appears when:

- The table name comes from a UDT parameter (`{BASCULA}`), **and**

- The query includes a condition with a tag reference (`{[.]../../GLOBAL/FechaHoraDia}`).

The tag returns:

```python
[null, Error_ExpressionEval("The statement did not return a result set.")]

```

It looks like the date condition causes the problem when combined with a table parameter.  
Has anyone seen this behavior before or knows why Ignition fails in this case?

Thanks!

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [November 3, 2025, 7:12pm UTC](https://forum.inductiveautomation.com/t/query-tag-parameter-udt/111908/2 "2025-11-03T19:12:51Z")

</div>

Have you tried putting `{BASCULA}` in quotes?

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [November 3, 2025, 7:16pm UTC](https://forum.inductiveautomation.com/t/query-tag-parameter-udt/111908/3 "2025-11-03T19:16:40Z")

</div>

I don’t think direct parameterization of the table name is allowed in SQL like that. I don’t normally use query tags, but have you tried using `QUOTENAME(OBJECT_NAME({BASCULA}))`

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [November 3, 2025, 7:36pm UTC](https://forum.inductiveautomation.com/t/query-tag-parameter-udt/111908/4 "2025-11-03T19:36:49Z")

</div>

I just tested this and it worked fine on 8.1.42

The only difference is that I used a parameter for the date and put it in quotes.

```python
SELECT TOP(1) [TableID]
FROM {TableName}
WHERE [TimeBegin] >= '{DateParam}'
ORDER BY [TimeBegin] DESC

```

What type of tag are you reading the date from? and are you sure of the convert?

---

<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:** [November 3, 2025, 7:41pm UTC](https://forum.inductiveautomation.com/t/query-tag-parameter-udt/111908/5 "2025-11-03T19:41:54Z")

</div>

I vaguely recall a bug related to query bindings that have both a UDT parameter and a tag reference, but I can't recall the details.

Related notes:

- Query tags cannot use proper/safe parameter substitutions (Prep query question marks, named query colon-delimited values). Curly braces are **string substitutions** without proper parameter handling.

- String substitution is necessary for SQL **structure** elements, like table and column names.

- String substitution is **dangerous** for SQL values, particularly when values are arbitrary and/or from external sources (like a PLC).

- Single quotes around string substitutions are required when the value injected is not purely numeric.

Basically, you should not be using a query tag for this case, since it needs proper parameterization. Unfortunately, with a UDT, you cannot scalably use gateway tag events (subscribed to all `FechaHoraDia`), which you need to safely run queries. Consider using scripted queries with my Integration Toolkit's **BulkScript** tag actor, which helps solve this problem.
