# Query broke after converting to named query

**URL:** <https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343>\
**Category:** Ignition\
**Created:** [May 5, 2023, 8:33pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343 "2023-05-05T20:33:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 5, 2023, 8:33pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/1 "2023-05-05T20:33:23Z")

</div>

I recently had an SQL Query assigned to an LED display value, in order to run the query in the client view I needed to change it to a Named Query so it would run on the gateway instead of on the client (permissions issue). When I copied the sql query and created a named query the query stopped returning the correct value. The query checks the DB based on operator submited text and returns a 1 or 0. What am I missing when I changed to a named query that would cause the query to return a 0 when it should have returned a 1?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [May 5, 2023, 8:42pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/2 "2023-05-05T20:42:11Z")

</div>

Share the query...

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 5, 2023, 8:42pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/3 "2023-05-05T20:42:41Z")

</div>

SELECT Decode(count(\*),0,0,1)  
FROM core\_batch\_report\_load  
where batch\_no = (select batch\_no from core\_app\_display\_data where batch\_no = '{Root Container.Batch Number Data.text}' and original\_serno = '{Root Container.Serial Number.text}')  
and inventory\_material = '{Root Container.Generic Data.text}'  
and batch\_no = '{Root Container.Batch Number Data.text}'

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 5, 2023, 8:46pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/4 "2023-05-05T20:46:25Z")

</div>

There's a button on the binding to change it into a named query; did you press that, or manually copy and paste?

The parameter substitution syntax is completely different between SQL bindings and named queries, in the sense that named queries...actually have a parameter substitution syntax. So the _query_ should be something like:

```sql
SELECT Decode(count(*),0,0,1)
FROM core_batch_report_load
where batch_no = (select batch_no from core_app_display_data where batch_no = ? and original_serno = ?)
and inventory_material = ?
and batch_no = ?

```

And at the _binding_, you'll pass in the different parameters you want.

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 5, 2023, 8:51pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/5 "2023-05-05T20:51:32Z")

</div>

I clicked the convert, but not sure what it is asking for when it says Enter path for select query.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 5, 2023, 8:53pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/6 "2023-05-05T20:53:13Z")

</div>

The path to the select query would be where the converted query landed. You should have a little helper tool to help you choose it, as well. About :55 seconds in here: [Named Query Binding Video at Inductive University](https://inductiveuniversity.com/video/named-query-binding/8.0)

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 5, 2023, 9:24pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/7 "2023-05-05T21:24:10Z")

</div>

Great! Thank you. This did not solve my issue. For some reason this query, SQL or Named works in local host but will not work once it is added to the gateway and opened in the client.

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 5, 2023, 9:25pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/8 "2023-05-05T21:25:21Z")

</div>

Sorry, this is a oracle SQL query that works in the designer but will not work in the client viewer.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [May 5, 2023, 10:15pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/9 "2023-05-05T22:15:22Z")

</div>

~~You need to enable "Legacy Database Access"~~

[https://docs.inductiveautomation.com/display/DOC81/Vision+Project+Properties#VisionProjectProperties-VisionPermissionsProperties](https://docs.inductiveautomation.com/display/DOC81/Vision+Project+Properties#VisionProjectProperties-VisionPermissionsProperties)

I was wrong 😬 Thanks for correcting me Paul

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 5, 2023, 10:36pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/10 "2023-05-05T22:36:58Z")

</div>

You don't need that for a properly converted named query.

I would recommend contacting support at this point, Chad. Or share some screenshots of how you've got everything set up _and_ the full details/stacktrace of the error you're seeing.

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 9, 2023, 6:59pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/11 "2023-05-09T18:59:57Z")

</div>

While trying to convert to a Named query What is the "Path for Select Query"? Not sure what to type there?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/4/c47734229a8db146b8a402a1bda42ae1afb40154.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 9, 2023, 7:21pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/12 "2023-05-09T19:21:50Z")

</div>

It's whatever you want to put. It will be used as the location for the new named query resource that gets generated. You should use whatever folder structure/naming convention you'll find maintainable in the future; slashes are allowed and will be turned into folders.

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 9, 2023, 7:23pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/13 "2023-05-09T19:23:07Z")

</div>

The error on the server I am getting is "The current user does not have the required roles for this". That is why I am trying to change it to a Named query, so the query runs on the gateway instead of the user running the query from the client.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/c/3c9a8092220b3d00d823c4d46c51cd871c8668d8.png)

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 9, 2023, 7:44pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/14 "2023-05-09T19:44:16Z")

</div>

Also getting the below message for the Named Query.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/3/a3e2d1772af9c16250975d80800596d9c1094e8b.png)

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 11, 2023, 7:35pm UTC](https://forum.inductiveautomation.com/t/query-broke-after-converting-to-named-query/73343/15 "2023-05-11T19:35:32Z")

</div>

Update: Thank you all for the help on this. I did find out the issue with the queries after I changed them to Named Queries. I had a permissions setting that was set to authenticated. By changing it back to public my queries began working in the client.
