-1

Im trying to select from MS Access Database table in python WHERE Itemname is equal to some particular string which is stored in variable , while comparing that string directly in where clause with LIKE operator it is working fine but when i`m trying to pass this string through variable it is showing me syntex error.

query = "SELECT *  FROM table1 WHERE table1.Itemname LIKE 'XYZ' "
cursor2.execute(query)

This is working fine

Itemname = "XYZ"
query = "SELECT *  FROM table1 WHERE table1.Itemname LIKE %s "
cursor2.execute(query,(Itemname,))
Itemname = "XYZ"
query = "SELECT *  FROM table1 WHERE table1.Itemname LIKE {}".format(Itemname)
cursor2.execute(query)

None of the Two above options are working ,Pls point out if there is any syntex problem

June7
  • 19,874
  • 8
  • 24
  • 34
  • 1
    Does this answer your question? [How do I use SQL parameters with python?](https://stackoverflow.com/questions/3410455/how-do-i-use-sql-parameters-with-python) – June7 Jul 09 '22 at 03:38

1 Answers1

0

This is working finally

Itemname = "XYZ"
query = "SELECT *  FROM table1 WHERE table1.Itemname = ? "
cursor2.execute(query,[itemname])