Adithya Balaji
Adithya Balaji

Reputation: 49

Error while passing Datetime as a parameter to a stored procedure with PyODBC

I need to execute a stored procedure from Python. I am using pyodbc to do that. The stored procedure requires a datetime parameter to be passed.

I am using the below code:

cursor.execute('exec [Data].[GetData]?',datetime.datetime.now())

I get the following error:

ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Implicit conversion from data type datetime to bigint is not allowed. Use the CONVERT function to run this query. (257) (SQLExecDirectW)')

What should I do ?

Upvotes: 0

Views: 899

Answers (1)

thirteen4054
thirteen4054

Reputation: 485

from datetime import datetime

cursor.execute('exec [Data].[GetData]?',datetime.now())

had the same error check your import

Upvotes: 1

Related Questions