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?

1 Answer 1

1

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

How to parameterize datestamp in pyODBC query?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.