# Delete from table script

**URL:** <https://forum.inductiveautomation.com/t/delete-from-table-script/6809>\
**Category:** Ignition\
**Created:** [July 2, 2013, 5:08pm UTC](https://forum.inductiveautomation.com/t/delete-from-table-script/6809 "2013-07-02T17:08:28Z")\
**Posts on this page:** 4\
**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:** [July 2, 2013, 5:08pm UTC](https://forum.inductiveautomation.com/t/delete-from-table-script/6809/1 "2013-07-02T17:08:28Z")

</div>

I’ve been trying to make a def block to delete old records from a database and I keep getting errors with this query.

`def clearData (tableName, noDays):
	import system, datetime
	system.db.runPrepUpdate("Delete from ? where t_stamp < getdate() - ?",[tableName, noDays])`

What am I missing?

---

<div class="post-metadata">

**Author:** ![markdobtech](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@markdobtech](https://forum.inductiveautomation.com/u/markdobtech)\
**Post date:** [July 3, 2013, 1:45pm UTC](https://forum.inductiveautomation.com/t/delete-from-table-script/6809/2 "2013-07-03T13:45:02Z")

</div>

Try this:  
system.db.runPrepUpdate(“Delete from %s where t\_stamp \< getdate() - ?” % tableName,[noDays])

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 3, 2013, 7:44pm UTC](https://forum.inductiveautomation.com/t/delete-from-table-script/6809/3 "2013-07-03T19:44:48Z")

</div>

Can’t use question marks for table names.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [July 6, 2013, 12:40am UTC](https://forum.inductiveautomation.com/t/delete-from-table-script/6809/4 "2013-07-06T00:40:42Z")

</div>

What errors are you getting? Can you post them?
