# Named Query Returning Output

**URL:** <https://forum.inductiveautomation.com/t/named-query-returning-output/83201>\
**Category:** Ignition\
**Tags:** namedqueries, perspective\
**Created:** [December 15, 2023, 6:31pm UTC](https://forum.inductiveautomation.com/t/named-query-returning-output/83201 "2023-12-15T18:31:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![S\_B](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@S\_B](https://forum.inductiveautomation.com/u/S_B)\
**Post date:** [December 15, 2023, 6:31pm UTC](https://forum.inductiveautomation.com/t/named-query-returning-output/83201/1 "2023-12-15T18:31:29Z")

</div>

Hello,

I am somewhat new to Ignition. We are using Perspective. On an Update I'd like to return an update parameter that is an Output.

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

IE if successful it returns 1 else 0.

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

When calling from a script I will check this variable if its 0 I can popup an error message, if 1 I can pass a Success message. I have the popups set up but cant figure out how to pass output parameters back in the script to know if it was rolledback or updated.

How are people currently doing this via Named Queries?

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

Or is there something built in that I know if its fully successful or not. Inserting into a changelog so there are over 8 update statements with inserts to changelog.

Thanks for any advice.

---

<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:** [December 15, 2023, 9:29pm UTC](https://forum.inductiveautomation.com/t/named-query-returning-output/83201/2 "2023-12-15T21:29:02Z")

</div>

It looks like maybe this is a snipit from your DB Managment system, if not then you should avoid SQL scripts, as SQL _ **scripting** _ isn't in the JDBC spec., even if some drivers tolerate them.

If this isn't already a stored procedure then it probably should be. There are multiple ways that a SP can be run from Ignition.

However, you should know that you can use `system.db.beginNamedQueryTransaction()` to create and run named queries in a transaction, you really don't need return the status of the transaction from the query. (If that is all the stored procedure is intended to do). If you do this, you should not use a transaction inside of the query or stored procedure.

Also, a named query by default returns the number of effected rows, which, would indicate if the transaction was committed or rolled back, as a rolled back transaction by definition can not effect any rows.

More information on when different tools for running queries in ignition should be used can be found here:

> [@runNamedQuery vs runPrepQuery](https://forum.inductiveautomation.com/t/runnamedquery-vs-runprepquery/81268/6):
>
> The original purpose of Named Queries was to make it possible to pass values into Vision Query bindings in a secure and efficient way, solving the unreliability of parameter stringification (looking at you, java.util.Date), and allowing the huge "legacy DB access" security hole to be closed. The maintenance advantages of NQs can be matched by multi-line strings for SQL in library scripts, so I tend to discount that item. However, not all is well. Some things to consider: NQs permit the use…

---

<div class="post-metadata">

**Author:** ![S\_B](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@S\_B](https://forum.inductiveautomation.com/u/S_B)\
**Post date:** [December 15, 2023, 10:00pm UTC](https://forum.inductiveautomation.com/t/named-query-returning-output/83201/3 "2023-12-15T22:00:40Z")

</div>

Yes, it is a stored procedure running from db management system.

Thanks this has given me an idea how to get this to work.

Appreciate the time it took you to reply.
