pymssql cursor execute parameterized query errors

36 Views Asked by At

when I try pymssql cursor.execute(query,parameter) with the following query, it works:

SELECT * 
FROM Accounts,Ident  
WHERE
 Accounts.Pat_ID1 = Ident.Pat_ID1 AND
 Ident.IDA = %(patient_id)s

The parameter is a dictionary {'patient_id'=23e344,'sqlTableName'='Accounts'}

but if I change the query to following with same parameter dictionary, I got error message b"Incorrect syntax near 'Accounts'.DB-Lib error message 20018. What is the problem? Thank you. John

SELECT * 
FROM %(sqlTableName)s,Ident  
WHERE
 %(sqlTableName)s.Pat_ID1 = Ident.Pat_ID1 AND
 Ident.IDA = %(patient_id)s
0

There are 0 best solutions below