SQL Query from Script - Can This be Done

Hello,

I am trying to pass variables into the query, this was working without making the column name a variable, but now I am trying to write a general case where it will use the custom value of each page to identify which column it should UPDATE.

queryValue = system.tag.read(’[PanelShop]JobNumSelect’).value

system.db.runPrepUpdate(""“UPDATE PanelShop.dbo.ActiveList SET %s = (?) WHERE JobNum = (?)”"" % str(event.source.Area) , [ 0, str(queryValue)])
##################################################################
This returns no error

I have also tried this:
runPrepUpdate(“UPDATE DATABASE SET (?) = (?) WHERE COLUMN1 = (?)” , [Argument1, arg2, arg3])

##################################################################

The query works if I just do:
(“UPDATE DATABASE SET COLUMN2 = (?) WHERE COLUMN1 = (?)” , [Argument1, arg2])

Help there is no error code

Column names and table names are part of the structure of a query, and cannot be substituted with ? placeholders. Those can only provide data to the query, not structure. You’ll need to use string interpolation for the column name. Note that the parentheses around your placeholders are not necessary.

3 Likes