The odbc module in Pythonwin uses qmark parameter style I believe, so use ? instead of %s for parameter substitution.
-------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre Operations Branch tel: +61 2 6219 5356 Communications Infrastructure Division fax: +61 2 6253 3277 Australian Communications & Media Authority email: andrew.macint...@acma.gov.au <mailto:andrew.macint...@acma.gov.au> http://www.acma.gov.au/ <http://www.acma.gov.au/> Tom Hawkins wrote I'm trying to get data out of a MS SQL Server 2005 database from a Python 2.5 script, using the odbc module - I can't easily get anything more up-to-date installed on this system. {...} ...it works OK, but if I try to parameterise the query: myQuery = """SELECT EnteredValue FROM SampleTests INNER JOIN SampleResults ON (SampleTests.SampleCode = SampleResults.SampleCode AND SampleTests.AuditFlag = SampleResults.AuditFlag AND SampleTests.TestPosition = SampleResults.TestPosition) WHERE (SampleTests.SampleCode=%s AND SampleTests.AuditFlag=0 AND SampleTests.TestCode=%s AND SampleTests.TestStatus<900 AND SampleResults.ComponentName='IntMethod') """ ... cursor.execute(myQuery, ('foo', 'bar')) ...I get: dbi.program-error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 's'. in EXEC Any idea what I'm doing wrong please? Apologies if I've missed something stupid. I get the same error if I only specify one of the parameters with %s and leave the other one literal, by the way. NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32