Had a long search through here and the web and can't seem to find any examples that explain why I am getting a syntax error on the following: import win32com.client
`
PregCode = recordsetraw.Fields.Item("PregnancyCode").value
SQL = "INSERT INTO UniqueData SELECT * FROM Rawdata WHERE PregnancyCode =%s"
params = (PregCode)
connection.execute(SQL, params)
print PregCode
recordsetraw.MoveNext()`
I'm getting the following error:
Traceback (most recent call last): File "testdb.py", line 22, in connection.execute(SQL, params) File "", line 2, in execute pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft JET D atabase Engine', u"Syntax error in query expression 'PregnancyCode = %s'.", None , 5003000, -2147217900), None)
I have tried hardcoding in PregnancyCode to see if that would make a difference but no, same error.
Any ideas what I'm doing wrong?
execute()needs to be a sequence. As written it is a single value. Use instead(PregCode,); note trailing comma. The comma makes it a tuple.