May-28-2019, 09:23 AM
Hello Python forum,
I'm new to python world. Please bear with me if my question sounds silly.
My problem statement : Passing parameter to SQL server using pandas.
Note: Have imported all the necessary library for pandas,datetime,pyodbc in my code
Sql_query = """ SELECT Top 10
TRIM([Insured Name]) AS [Insured Name] From
tblPremiumRegisterReport Where
cast(dtInforceDate as date) between cast(@dtFrom as date) and cast(@dtUpto as date)"""
pd.read_sql(Sql_query,con=conn,params={'@dtFrom':date.today(),'@dtUpto':date.today()})
Getting below error:
I'm new to python world. Please bear with me if my question sounds silly.
My problem statement : Passing parameter to SQL server using pandas.
Note: Have imported all the necessary library for pandas,datetime,pyodbc in my code
Sql_query = """ SELECT Top 10
TRIM([Insured Name]) AS [Insured Name] From
tblPremiumRegisterReport Where
cast(dtInforceDate as date) between cast(@dtFrom as date) and cast(@dtUpto as date)"""
pd.read_sql(Sql_query,con=conn,params={'@dtFrom':date.today(),'@dtUpto':date.today()})
Getting below error:
Error:ProgrammingError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\sql.py in execute(self, *args, **kwargs)
1377 else:
-> 1378 cur.execute(*args)
1379 return cur
ProgrammingError: ('The SQL contains 0 parameter markers, but 1 parameters were supplied', 'HY000')
During handling of the above exception, another exception occurred:
DatabaseError Traceback (most recent call last)
<ipython-input-144-11ba7d565e99> in <module>()
2 TRIM([Insured Name]) AS [Insured Name] From
3 tblPremiumRegisterReport Where
----> 4 cast(dtInforceDate as date) between cast(@fromdate as date) and cast(@Uptodate as date)""",con=conn,params={'@dtFrom':date.today(),'@dtUpto':date.today()})