Delete from table script

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?

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

Can’t use question marks for table names.

What errors are you getting? Can you post them?