【发布时间】:2017-03-04 00:21:56
【问题描述】:
我试图在 sql 查询中传递三个变量。这些是区域、功能、新用户。我正在使用 SQL 驱动程序 SQL Server Native Client 11.0。
这是我的有效代码。
query = "SELECT LicenseNo FROM License_Mgmt_Reporting.dbo.MATLAB_NNU_OPTIONS WHERE Region = ?"
data_df = pd.read_sql_query((query),engine,params={region})
输出。
LicenseNo
0 12
1 5
相反,我想传入三个变量,但这段代码不起作用。
query = "SELECT LicenseNo FROM License_Mgmt_Reporting.dbo.MATLAB_NNU_OPTIONS WHERE Region = ? and FeatureName = ? and NewUser =?"
nnu_data_df = pd.read_sql_query((query),engine,params={region, feature, newUser})
输出返回一个空数据框。
Empty DataFrame
Columns: [LicenseNo]
Index: []
【问题讨论】:
标签: python sql-server pandas parameter-passing