# SQL Server Update Query: Is it possible to get the return code?

**URL:** <https://forum.inductiveautomation.com/t/sql-server-update-query-is-it-possible-to-get-the-return-code/100119>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 20, 2024, 6:45pm UTC](https://forum.inductiveautomation.com/t/sql-server-update-query-is-it-possible-to-get-the-return-code/100119 "2024-12-20T18:45:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [December 20, 2024, 6:45pm UTC](https://forum.inductiveautomation.com/t/sql-server-update-query-is-it-possible-to-get-the-return-code/100119/1 "2024-12-20T18:45:13Z")

</div>

I am wondering if it's possible to get the return code from the stored procedure when I run an update query. "Update", in this context, is the Ignition query type, the actual procedure runs a couple of insert statements.

Stored Procedures return a code, depending on success or failure, and I would like to get the zero code on success to tell the user that the inserts were successful.

The update query takes a bunch of parameters, sends those to the sproc.

```python
query = 'myUpdateQuery'
params = {about 40 items...}
system.perspective.runNamedQuery(query, params)

```

Query statement:

```python
EXEC dbo.usp_InsertSurveyData :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, 
	:p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20, :p21, :p22, :p23, :p24, :p25, :p26,  
	:p27, :p28, :p29, :p30, :p31, :p32, :p33, :p34, :p35, :p36, :p37, :p38, :p39, :dept, :shift, :position 

```

If I change this to a "Scalar Query" and attempt to get the result...it does not work.

Anyone know of a way to do this?

---

<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:** [December 20, 2024, 9:05pm UTC](https://forum.inductiveautomation.com/t/sql-server-update-query-is-it-possible-to-get-the-return-code/100119/2 "2024-12-20T21:05:47Z")

</div>

Did you check the return code you are currently getting?

(You may need to script the procedure call and use an output parameter. Named queries can't do that.)

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [December 27, 2024, 5:54pm UTC](https://forum.inductiveautomation.com/t/sql-server-update-query-is-it-possible-to-get-the-return-code/100119/3 "2024-12-27T17:54:07Z")

</div>

well, the only return code I get by default is zero. Unless I specify the return code like `RETURN 4`, I get `0`. But this I do in the SSMS.

Is there a "best practice" for getting a confirmation of an update/insert? Would that be the scripting you mentioned?

---

<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:** [December 27, 2024, 8:25pm UTC](https://forum.inductiveautomation.com/t/sql-server-update-query-is-it-possible-to-get-the-return-code/100119/4 "2024-12-27T20:25:28Z")

</div>

> [@mdemaris](#):
>
> code like `RETURN 4`,

That's SQL _ **scripting** _. Don't do that.

Just use a plain SQL INSERT or UPDATE **statement** (no DECLAREs or BEGINs or other SQL script syntax) and you will automatically get the number of affected rows as the return value.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [October 7, 2025, 12:38am UTC](https://forum.inductiveautomation.com/t/sql-server-update-query-is-it-possible-to-get-the-return-code/100119/5 "2025-10-07T00:38:46Z")

</div>

And how do I get this returned value into Ignition?

---

<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:** [October 7, 2025, 12:58am UTC](https://forum.inductiveautomation.com/t/sql-server-update-query-is-it-possible-to-get-the-return-code/100119/6 "2025-10-07T00:58:56Z")

</div>

Most things in `system.*.*` are _ **functions** _. Use `retv = system.some.thing(...)` to collect a return value into a local python variable.
