Nov-02-2021, 11:00 AM
(This post was last modified: Nov-02-2021, 03:17 PM by Yoriz.
Edit Reason: Added code tags
)
I am having an error how resolve this
import pyodbc import datetime conn = pyodbc.connect('Driver={SQL Server};' 'Server=DESKTOP-MBJNNJR;' 'Database=master;' 'Trusted_Connection=yes;') cursor = conn.cursor() cursor.execute('SELECT Employee_Name, Hire_Date FROM Employee WHERE Hire_Date BETWEEN [{%s}] AND [{%s}]') hire_start = datetime.date(1999, 1, 1) hire_end = datetime.date(1999, 12, 31) cursor.execute(query, (hire_start, hire_end)) for (Employee_Name, Hire_Date) in cursor: print("{}, {} was hired on {:%d %m %Y}".format(Employee_Name, Hire_Date)) cursor.close()
Error:ProgrammingError: ('42S22', "[42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name '{%s}'. (207) (SQLExecDirectW); [42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name '{%s}'. (207)")