# Named query works in testing, but not with a binding

**URL:** <https://forum.inductiveautomation.com/t/named-query-works-in-testing-but-not-with-a-binding/98670>\
**Category:** Ignition\
**Created:** [November 15, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/named-query-works-in-testing-but-not-with-a-binding/98670 "2024-11-15T15:49:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Esposito](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Chris\_Esposito](https://forum.inductiveautomation.com/u/Chris_Esposito)\
**Post date:** [November 15, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/named-query-works-in-testing-but-not-with-a-binding/98670/1 "2024-11-15T15:49:49Z")

</div>

I have a simple named query that works via the Testing tab on the query builder. I can test it with: TownA as Plant and I get results I expect:

```python
SELECT [MachineID]
FROM machines
WHERE [Target] - [Bag] = 0 
AND [State] NOT IN(4, 65535, 56, 1)
AND (
    (:Plant = 'TownA' AND [RoomCode] LIKE 'WB%')
    OR 
    (:Plant = 'TownB' AND [RoomCode] NOT LIKE 'WB%')
)
ORDER BY MachineID ASC

```

When I attempt to bind the query to a label, I get the error:  
Error\_Configuration("RuntimeException: Syntax Error on Token 'End of Expression' (Line 0, Char0)")

This happens when I put the Plant value in without quotes( TownA ), as I've tested with in the query builder.

If I I surround the Plant value with quotes in the binding ( "TownA" ), it accepts it. However, I get an empty dataset as the result, since with quotes my query doesn't match, and doesn't return results. (If I test with quotes in the query builder, I also get no results).

How can I get this to work? It seems like it should be simple, but I'm not getting anywhere with it.

---

<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 15, 2024, 3:58pm UTC](https://forum.inductiveautomation.com/t/named-query-works-in-testing-but-not-with-a-binding/98670/2 "2024-11-15T15:58:34Z")

</div>

> [@Chris\_Esposito](#):
>
> `:Plant = 'TownA'`

This seems backwards to me. Why would it not be something like

```python
[Plant] = :Plant

```

You would provide `TownA`, `TownB`, etc. as the `Plant` parameter.

---

<div class="post-metadata">

**Author:** ![Chris\_Esposito](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Chris\_Esposito](https://forum.inductiveautomation.com/u/Chris_Esposito)\
**Post date:** [November 15, 2024, 4:14pm UTC](https://forum.inductiveautomation.com/t/named-query-works-in-testing-but-not-with-a-binding/98670/3 "2024-11-15T16:14:31Z")

</div>

The query isn't really the problem. It tests fine, but I'm not able to use the query in the binding. I have tried doing the query other ways (which also give me the expected results in the testing tab of the query builder), but I run into the same issue when attempting to use a binding.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 15, 2024, 4:24pm UTC](https://forum.inductiveautomation.com/t/named-query-works-in-testing-but-not-with-a-binding/98670/4 "2024-11-15T16:24:53Z")

</div>

You are going to have to show how you are providing these parameters to your named query, the bindings.

---

<div class="post-metadata">

**Author:** ![Chris\_Esposito](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Chris\_Esposito](https://forum.inductiveautomation.com/u/Chris_Esposito)\
**Post date:** [November 15, 2024, 5:52pm UTC](https://forum.inductiveautomation.com/t/named-query-works-in-testing-but-not-with-a-binding/98670/5 "2024-11-15T17:52:12Z")

</div>

It's working now...It seems I just needed to hit save after creating the query before it was really functional in Designer.
