# Trouble using runPrepQuery and wildcard after SELECT

**URL:** <https://forum.inductiveautomation.com/t/trouble-using-runprepquery-and-wildcard-after-select/7645>\
**Category:** Ignition\
**Created:** [November 30, 2013, 8:22pm UTC](https://forum.inductiveautomation.com/t/trouble-using-runprepquery-and-wildcard-after-select/7645 "2013-11-30T20:22:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RossStewart](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@RossStewart](https://forum.inductiveautomation.com/u/RossStewart)\
**Post date:** [November 30, 2013, 8:22pm UTC](https://forum.inductiveautomation.com/t/trouble-using-runprepquery-and-wildcard-after-select/7645/1 "2013-11-30T20:22:36Z")

</div>

LT= system.db.runPrepQuery(“SELECT CHM1SP FROM stimprogram WHERE Target = ?”, [TT], “CHCFG”)  
print LT[0][0]  
produces the result of the value stored in DB (42.0)

x= “CHM1SP”  
LT= system.db.runPrepQuery(“SELECT ? FROM stimprogram WHERE Target = ?”, [x,TT], “CHCFG”)  
print LT[0][0]  
produces the result “CHM1SP”

Any Idea Why?

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [November 30, 2013, 9:44pm UTC](https://forum.inductiveautomation.com/t/trouble-using-runprepquery-and-wildcard-after-select/7645/2 "2013-11-30T21:44:15Z")

</div>

The parameters are quoted when run in a prepared statement, so your query is interpreted as SELECT “CHM1SP” …  
You may use python string substitution in this case:

```auto
system.db.runPrepQuery("SELECT %s FROM..." % (x), ...)
```

---

<div class="post-metadata">

**Author:** ![RossStewart](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@RossStewart](https://forum.inductiveautomation.com/u/RossStewart)\
**Post date:** [December 2, 2013, 5:31pm UTC](https://forum.inductiveautomation.com/t/trouble-using-runprepquery-and-wildcard-after-select/7645/3 "2013-12-02T17:31:20Z")

</div>

Wow the littlest things can ruin your Saturday,

Thanks for the help, it worked. ![:thumb_right:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/2026e28c0c425034352c1b75807edf956adc75f4.gif ":thumb\_right:")
