Having trouble passing parameters to a SQL Server query. The query works with raw data, but not when I try to use parameters. SQL is not identifying parameter markers.
The error I get is
The SQL contains 0 parameter markers, but 2 parameters were supplied', 'HY000'
This is my code I'm having issues with:
currenttime = datetime.datetime(year=2021, month=6, day=7, hour=7, minute=0, second=0, microsecond=999999)
print(currenttime)
print(type(currenttime))
starttime = currenttime = datetime.datetime(year=2021, month=6,day=7,hour=6,minute=0,second=0,microsecond=999999)
params = (starttime,currenttime)
sql='''
SET QUOTED_IDENTIFIER OFF
SELECT * FROM OPENQUERY(INSQL, "SELECT DateTime, [AH41_DP04]
FROM WideHistory
WHERE wwRetrievalMode = 'Cyclic'
AND wwResolution = 1000
AND wwVersion = 'Latest'
AND DateTime >= ?
AND DateTime <= ?")
'''
print(type(params))
cursor.execute(sql,params)
for row in cursor:
print(row)``