0

A similar question was asked. The goal is to create the function described here:

def DB_Query(d1, d2):
    conn = pyodbc.connect('DSN=DATASOURCE')
    tbl = "SELECT TableA.Field_1 \
    FROM TableA \
    WHERE TableA.Date>=? AND TableA.Date<=?"
    df_tbl= pd.read_sql_query(tbl, conn, params = (d1,d2))
    conn.close
    return df_tbl

This worked on database with SQL Server driver, but it won't work on Microsoft ODBC for Oracle driver.

When I give, for e.g., d1 = '2020-02-20' and d2 = '2020-02-25', I get error ('HY004', '[HY004] [Microsoft][ODBC Driver Manager] SQL data type out of range (0) (SQLBindParameter)')

I understand in Oracle, you need DATE 'YYYY-MM-DD' to express a date, which is different from SQL server where you can just use 'YYYY-MM-DD'.

I've tried add DATE in front of ? but doesn't work. Any ideas?

chen
  • 97
  • 1
  • 10

1 Answers1

1

Found solution here. Just define d1 as date(2020,02,20).

How to parameterize datestamp in pyODBC query?

chen
  • 97
  • 1
  • 10