Python Forum
Passing parameters to SQL Server using pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing parameters to SQL Server using pandas
#1
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:
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()})
Reply


Messages In This Thread
Passing parameters to SQL Server using pandas - by Ilangos - May-28-2019, 09:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 771 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Passing parameters with arrays and array definitions michael_lwt 1 973 Jul-07-2022, 09:45 PM
Last Post: Larz60+
  How to take the tar backup files form remote server to local server sivareddy 0 1,937 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Fastest Method for Querying SQL Server with Python Pandas BuJayBelvin 7 7,003 Aug-02-2020, 06:21 PM
Last Post: jefsummers
  Passing parameters from C# to Python[for using in gensim] in Visual Studio 2017 ZoghbyAya 0 3,887 May-21-2018, 08:49 PM
Last Post: ZoghbyAya

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020