我被卡住了 - 我有下面的SQL鍊金術的Python腳本,我已經很成功地用於其他幾個目的。SQLAlchemy使用包含@DECLARE本地表的原始SQL執行
import sqlalchemy
from sqlalchemy import MetaData
from sqlalchemy.orm import *
engine = sqlalchemy.create_engine("this line of code would provide credentials to the database")
connection = engine.connect()
session = sessionmaker(bind=engine)
result = connection.execute(sqlquery)
for row in result: print row
但是最近我發現,如果我的「sqlquery的」包含@Declare MyTable的發言中,我得到的錯誤:
"This result object does not return rows. "
sqlalchemy.exc.ResourceClosedError: This result object does not return rows. It has been closed automatically.
這裏是我的SQL查詢其作品在SSMS罰款,但不會執行時我嘗試使用SQLAlchemy的
執行它DECLARE @USER TABLE
(
UserID INT
, StatsVals INT
)
INSERT INTO @USER (UserID, StatsVals)
SELECT TOP 10 u.UserID
, u.StatsVals
FROM UserProfile u
SELECT * FROM @USER
有誰知道爲什麼SQLAlchemy的是給我這個錯誤?我應該怎麼做才能解決這個問題?