# Run query in UDT

**URL:** <https://forum.inductiveautomation.com/t/run-query-in-udt/6201>\
**Category:** Ignition\
**Created:** [April 10, 2013, 3:16pm UTC](https://forum.inductiveautomation.com/t/run-query-in-udt/6201 "2013-04-10T15:16:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [April 10, 2013, 3:16pm UTC](https://forum.inductiveautomation.com/t/run-query-in-udt/6201/1 "2013-04-10T15:16:17Z")

</div>

Can I run an Update query as an expression tag like

```auto
runScript(app.Winchester.DowntimeQuery.query("MOTOR_1008"), 1000)
```

then the script is:

`def query(Motor):
	import system
	run = 5
	faults = 6
	system.db.runUpdateQuery("UPDATE Conveyordesc SET Runtime = '%s', Faults = '%s' WHERE motorID = '%s'" % (run, faults, Motor), 'SQLServer')
	return 0`

I’d like to be able to consistantly update my table for each UDT instance of motors

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [April 10, 2013, 3:46pm UTC](https://forum.inductiveautomation.com/t/run-query-in-udt/6201/2 "2013-04-10T15:46:06Z")

</div>

You can’t call app script function inside of tags. Tags are stored on the gateway and executed there outside of a project. So they don’t have access to those functions. However, you should be able to do a runScript calling the system function:`runScript("system.db.runUpdateQuery(\"UPDATE Conveyordesc SET Runtime = '5', Faults = '6' WHERE motorID = 'MOTOR_1008'\", 'SQLServer')", 1000)`You can put in dynamic values like this:`runScript("system.db.runUpdateQuery(\"UPDATE Conveyordesc SET Runtime = '5', Faults = '6' WHERE motorID = '" + {Path/To/Tag} + "'\", 'SQLServer')", 1000)`

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [April 10, 2013, 5:17pm UTC](https://forum.inductiveautomation.com/t/run-query-in-udt/6201/3 "2013-04-10T17:17:59Z")

</div>

thanks Travis
