I'm stuck -- I have the following python script with SQL alchemy which I've been using quite successfully for several other purposes.
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
Recently though I discovered that if my 'sqlquery' contains an @Declare MyTable statement I get the error:
"This result object does not return rows. "
sqlalchemy.exc.ResourceClosedError: This result object does not return rows. It has been closed automatically.
Here is my SQL query which works fine in SSMS but will not execute when I try to execute it using 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
Does anyone know why SQLAlchemy would be giving me this error? What should I do to fix this?