pandas中存储过程不同的数据库--Sql server

时间:2017-10-10 11:10:11

标签: python sql-server pandas

直接在python中输入sql命令时,运行此代码段可以正常工作。

cnxn = pyodbc.connect(driver and login details go here)
sql = """ sql command that produces a table from the main database """
df = pd.io.sql.read_sql_query(sql, cnxn)

然而,当我尝试运行与存储过程相同的代码时,数据帧返回'TypeError:'NoneType'对象不可迭代'。

sql = " Use database2 exec dbo.Open_Accounts "

我也知道你不能在pyodbc中使用go命令

USE [database2]
GO
EXEC    [dbo].[Open_Accounts]
GO

因而无法直接使用SQL代码。

1 个答案:

答案 0 :(得分:0)

EXEC Database2..Open_Accounts ?? --IF ANy参数那里。

相关问题