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

**URL:** <https://forum.inductiveautomation.com/t/resolution-for-error-must-declare-the-variable-p0/17020>\
**Category:** General Discussion\
**Tags:** database\
**Created:** [February 16, 2018, 8:58pm UTC](https://forum.inductiveautomation.com/t/resolution-for-error-must-declare-the-variable-p0/17020 "2018-02-16T20:58:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [February 16, 2018, 8:58pm UTC](https://forum.inductiveautomation.com/t/resolution-for-error-must-declare-the-variable-p0/17020/1 "2018-02-16T20:58:24Z")

</div>

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

> ColumnTableName = system.tag.read("WaterJet/BarcodeBTableName").value  
> ColumnIDName = system.tag.read("WaterJet/BarcodeBColIDname").value  
> ColumnIDvalue = system.tag.read("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:

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c1ae4ba6c8e269b536adce63e54be865364bebce.png)

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

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6df8418b4b2fc055a8adf0d61d7b3439d6861e73.png)

The reason why you get this error is according to this [link](https://stackoverflow.com/questions/5895589/linq-to-sql-why-cant-i-use-table-name-as-parameter):  
@ before the "" says to compiler that this is a string nothing else  
Read it here [http://msdn.microsoft.com/en-us/library/362314fe(v=vs.71).aspx](http://msdn.microsoft.com/en-us/library/362314fe(v=vs.71).aspx)  
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](http://en.wikipedia.org/wiki/SQL_injection)  
[sql - "Must declare the table variable "@name"" in stored procedure - Stack Overflow](https://stackoverflow.com/questions/20265023/must-declare-the-table-variable-name-in-stored-procedure)

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):

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/293d391bdcadd7715a8b50594bd02f7ebf5bf7a1.png)  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/0911909e7566aa25f85ea952f49e9c83a906bf30.png)  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/40f3fc4198ce3f971b63df942bde42457998ef41.png)

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,

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 16, 2018, 9:16pm UTC](https://forum.inductiveautomation.com/t/resolution-for-error-must-declare-the-variable-p0/17020/2 "2018-02-16T21:16:21Z")

</div>

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?
