1

I am able to insert and replace the data in my MySQL table.

But I want to update the column dLieferdatum if the column sku equals cArtNr.

The Excel file looks as follows:

Excel Table

My Python Code:

cursor = connection.cursor()
query = """UPDATE d032683a.jll99_deliverytime_import SET dLieferdatum %s WHERE sku = %s"""

for r in range(1, sheet.nrows):
                cArtNr        = sheet.cell(r,1).value
                dLieferdatum  = sheet.cell(r,2).value


                values = (dLieferdatum, cArtNr)

                cursor.execute(query, values)

connection.commit()
cursor.close()
connection.close()

My Compiler (cygwin) error message:

Traceback (most recent call last): File "sql_update.py", line 63, in cursor.execute(query, values) pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''2020-05-29' WHERE sku = '11330342'' at line 1")

Many thanks and best regards.

2
  • SET dLieferdatum = %s ....... = is a mandatory part of the syntax. Commented May 20, 2020 at 12:42
  • ... *facepalm ... Thank you so much! I bet I would have never noticed it :-) Commented May 20, 2020 at 12:46

1 Answer 1

2

I think you are missing an equal sign in the update statement and that is why you are getting the error. I think if you add equal sign then you should be fine.

Also,if I were you, I would print the query in the console to see what is the exact query that is being sent to database and also for testing might run that query directly in database.

UPDATE d032683a.jll99_deliverytime_import SET dLieferdatum = %s WHERE sku = %s

You print(query) should look like below:

UPDATE d032683a.jll99_deliverytime_import SET dLieferdatum = '2020-05-29' WHERE sku = '11330342'
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Yes... I forgot the "=" between dLieferdatum %s

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.