I have a SQL Server table with the following columns (* indicates NULLs are allowed):
- ID (int)
- RequisitionID (int)
- ApplicantID (int)
- WorkflowStateID (int)
- WorkflowDate (datetime)
- SubmissionDate (datetime)
- StartDate (date)*
- DispositionID (int)*
- ATSApplicationID (varchar(255))*
- ApplicationLink (varchar(255))*
- CreateDate (datetime)
- ModifyDate (datetime)
I am attempting a parameterized INSERT query using pypyodbc with Driver=SQL Server (MS SQL Server 2012 database). Here is the query:
sql_statement = """
UPDATE [hr].[ATS.Applications] SET RequisitionID = ?, WorkflowStateID = ?, WorkflowDate = ?, StartDate = ?, DispositionID = ?, ModifyDate = ? WHERE ID = ?
"""
cursor.execute(sql_statement,(new_application.requisition_id,
new_application.workflow_state,
new_application.workflow_date.strftime("%Y-%m-%dT%H:%M:%S"),
new_start_date,
new_application.disposition,
now,
old_application.ID))
cursor.commit()
Resulting in the following error:
DataError: (u'22018', u'[22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: int is incompatible with date')
I assume one of the date strings is being interpreted as a calculated integer, however using the debugger, all data & data types appear to be compatible with my table:
new_application.requisition_id = {int} 7
new_application.workflow_state = {int} 19
new_application.workflow_date.strftime("%Y-%m-%dT%H:%M:%S") = {str} '2017-05-09T07:52:13'
new_start_date = {NoneType} None
new_application.disposition = {int} 7
now = {str} '2017-05-09T17:55:27'
old_application.ID = {int} 34402
I've tried inserting datetime values as both datetime objects and strings, and can't seem to resolve what data type it's expecting.
Any ideas why I am having issues with this UPDATE statement?
datetime
objects for query bindings – Azat Ibrakov