+ 2

Variables in SQL

Python for Sql database: Connection to database and so on... Variable = * Variable2 =.... cursor.execute("SELECT Variable FROM table WHERE Variable2....") I cant figure out, how to use variables in the sql-statement.

4th Sep 2020, 12:06 PM
Fu Foy
Fu Foy - avatar
3 Respostas
+ 3
Go to the link below, and scroll a bit, you'll get your answer. Happy coding <^_^> https://pynative.com/JUMP_LINK__&&__python__&&__JUMP_LINK-sqlite-insert-into-table/#:~:text=You%20can%20take%20those%20values,used%20for%20parameters.
4th Sep 2020, 12:38 PM
Charitra
Charitra - avatar
+ 1
import mysql import mysql.connector ... ... SearchString= "somestring" Query = """SELECT * FROM table WHERE category = %s """ cursor.execute(Query , (SearchString)) What's wrong with my code? I have also tried: '%s', "%s" ... Any ideas, anyone?
6th Sep 2020, 3:10 PM
Fu Foy
Fu Foy - avatar
+ 1
got it 1min later: cursor.execute("SELECT * FROM table WHERE category = '%s'",% searchstring) hope, it's helpful to someone in the future
6th Sep 2020, 3:15 PM
Fu Foy
Fu Foy - avatar