# Running SQL Stored Procedures in Script

**URL:** <https://forum.inductiveautomation.com/t/running-sql-stored-procedures-in-script/19096>\
**Category:** Ignition\
**Tags:** ignition79, database, scripting\
**Created:** [August 3, 2018, 9:03pm UTC](https://forum.inductiveautomation.com/t/running-sql-stored-procedures-in-script/19096 "2018-08-03T21:03:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jarredutt](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jarredutt/32/5393_2.png) [@jarredutt](https://forum.inductiveautomation.com/u/jarredutt)\
**Post date:** [August 3, 2018, 9:03pm UTC](https://forum.inductiveautomation.com/t/running-sql-stored-procedures-in-script/19096/1 "2018-08-03T21:03:05Z")

</div>

Hello all,

So I have a power table that shows all of the relevant data from whatever table is being queried. One of my requirements is to make that data editable in the power table and write the new value back to the SQL database. This part works fine, but I also have to call a stored procedure that takes the updated value and returns a matching UUID from an external SQL database. For some reason, I cannot get the stored procedure to execute. I confirmed this by digging through my database services to see what all had been called in my testing time frame. Below is my script, which is consistent with the Ignition Documentation. This script lives in the “onCellEdited” part of extension functions for Power Tables.

#update path (not really important for the question)  
tableName = ‘SiteLocal’  
id = self.data.getValueAt(rowIndex, ‘SiteLocalID’)  
query = 'UPDATE SiteLocal SET ’ +colName + ‘= ? WHERE SiteLocalID = ?’  
args = [newValue, id]  
system.db.runPrepUpdate(query,args, ‘MasterData\_R2’)  
system.db.refresh(self, ‘data’)  
#run stored procedure (below is where my problem lies)  
proc = system.db.createSProcCall(“dbo.local\_UpdateLocalElementUUIDs”)  
proc.registerInParam(‘TableName’, system.db.VARCHAR, tableName)  
proc.registerInParam(‘LocalId’, system.db.VARCHAR, id)  
system.db.execSProcCall(proc)

If you need any more information I can try to supply it… Thanks in advance!

Best,

Jarred

---

<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:** [August 4, 2018, 1:42pm UTC](https://forum.inductiveautomation.com/t/running-sql-stored-procedures-in-script/19096/2 "2018-08-04T13:42:01Z")

</div>

Are you running them inline in the script?  
If so, the system.db.refresh call will Null your id variable before it gets to the stored procedure call.
