Trouble using runPrepQuery and wildcard after SELECT

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?

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:

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

Wow the littlest things can ruin your Saturday,

Thanks for the help, it worked. :thumb_right: