我在 Python/pandas 中使用以下代码,有时我获取数据,有时它返回一个空的 DataFrame。不确定这里出了什么问题,但如果我在 read_sql_query
中传递多个参数,这似乎是一些错误:
query = "Select [C1], [LIFE_CYCLE] from TBL_NAME with(NOLOCK) where C1 = ? and (LIFE_CYCLE = ? or LIFE_CYCLE = ?)"
result = pd.read_sql_query(query, cnxn, params={'ABC','Account Live','Onboarding in progress'})
当我如下更改时,每次都可以正常工作:
query = "Select [C1], [LIFE_CYCLE] from TBL_NAME with(NOLOCK) where C1 = ? and (LIFE_CYCLE = 'Account Live' or LIFE_CYCLE = 'Onboarding in progress')"
result = pd.read_sql_query(query, cnxn, params={'ABC'})
版本:pandas==1.2.4,pyodbc==4.0.30