Resolution for Error: Must declare the variable "@P0"

I was running a query Script when a pressed button is pressed:

ColumnTableName =“WaterJet/BarcodeBTableName”).value
ColumnIDName =“WaterJet/BarcodeBColIDname”).value
ColumnIDvalue =“WaterJet/BarcodeBidValue”).value
Count = 15

query = “Update ? SET Count = ? Where ? = ?”
args = [ColumnTableName, count,DatetimeTable,ColumnIDName,ColumnIDvalue]
update = system.db.runPrepUpdate(query,args)
print update

I obtained the following error:

Then, still getting erros when testing it the Script Console:

The reason why you get this error is according to this link:
@ before the “” says to compiler that this is a string nothing else
Read it here
Must declare the table variable “@p0” seems to be different
Edited: Dont use table name as a parameter better use your table name only,it will cause sql injection please read
SQL injection - Wikipedia
sql - "Must declare the table variable "@name"" in stored procedure - Stack Overflow

One Solution:
You can try a different approach, by first testing your code in the Script Console: My Table name and the Column name will be change dynamically by using this (see the highlighted):

If anyone has a better approach in how to dynamically changing the name of the table and Column, will be very much appreciated.

Thank you,

You cannot use question-mark substitution for table or column names or any other structural part of your SQL. They can only be used for values. You will have to use string concatenation or interpolation to construct a query with variable identifiers.
Having to do so often means you are doing something wrong/dangerous, though. What exactly are you trying to do?

1 Like

Thank you! Now, I now :slight_smile: haha