jeudi 17 septembre 2015

Passing query parameters in Pandas

Trying to write a simple pandas script which executes a query from SQL Server with WHERE clause. However, the query doesnt return any values. Possibly because the parameter is not passed? I thought we could pass the key-value pairs as below. Can you please point out what i am doing wrong here?

Posting just the query and relevant pieces. All the libraries have been imported as needed.

  curr_sales_month = '2015-08-01'
  sql_query = """SELECT sale_month,region,oem,nameplate,Model,Segment,Sales  FROM [MONTHLY_SALES] WHERE Sale_Month = %(salesmonth)s"""
    print ("Executed SQL Extract", sql_query)

    df = pd.read_sql_query(sql_query,conn,params={"salesmonth":curr_sales_month}) 

The program returned with: Closed Connection - Fetched 0 rows for Report

    Process finished with exit code 0

Aucun commentaire:

Enregistrer un commentaire