I am using a raw_connection in sqlalchemy to execute some SQL that runs a stored procedure.
the stored proc selects a parameter ID at the end. How can I catch this ID?
the python code is:
import sqlalchemy as sa
SQLCommand = """
DECLARE @Msg varbinary(max) = CAST(%s AS varbinary(max) )
EXECUTE dbo.usp_procedure @Type = 32, @header = %s, @store = @Msg
""" % (Datacontent, var)
Engine = sa.create_engine(connection_string)
Connection = Engine.raw_connection()
cursor = Connection.cursor()
cursor.execute(SQLCommand)
return_key = list(cursor.fetchall())
Connection.commit()
Connection.close()
I thought return_key would contain the return code from usp_procedure but it errors out and I get:
No results. Previous SQL was not a query.
The procedure has as a final step:
SELECT @ParamID
I want to be able to read this code back in my python code