cursor.execute is a Python command. This is a Microsoft SQL Server forum, not a Python forum. Please post your question on a Python forum.
Must declare the scalar variable @P160R

I noticed sometimes, when I try to retrieve data using the sql format of:
self.cursor.execute('SELECT FROM tablename WHERE column1 LIKE ? OR column2 LIKE ? OR column3 LIKE ?' , (searchbox, searchbox, searchbox) )
It usually gives me an error message: ODBC SQL server (SQL Server) Must declare the scalar variable "P160R". [SQL Server statement could not be prepared]
What sort of shit is this?
3 answers
Sort by: Most helpful
-
-
MelissaMa-MSFT 24,136 Reputation points
2021-09-14T03:19:18.18+00:00 Hi @CEO ,
It seems that you use Python to retrieve data .
Please have a try like below, replace apostrophe with double quotes and make three searchboxes different.
cursor.execute("SELECT FROM tablename WHERE column1 LIKE ? OR column2 LIKE ? OR column3 LIKE ?" , (searchbox1, searchbox2, searchbox3) )
ODBC SQL server (SQL Server) Must declare the scalar variable "P160R". [SQL Server statement could not be prepared]
You could find out where is "P160R" from. It is from one procedure,function or other.
Then you could troubleshoot the relationship between the select statement and variable "P160R".
You could also use a new verison of ODBC driver and have another try.
Please provide more details then we could check further.
Thank you for understanding!
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. -
Tom Phillips 17,631 Reputation points
2021-09-14T14:51:04.227+00:00 My guess is one of the values you are passing is "P160R", and you probably need something like:
self.cursor.execute('SELECT FROM tablename WHERE column1 LIKE ''?'' OR column2 LIKE ''?'' OR column3 LIKE ''?''' , (searchbox, searchbox, searchbox) )