l******9 发帖数: 579 | 1 【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: get value returned by SQLstored procedure from python
发信站: BBS 未名空间站 (Fri Aug 1 18:07:59 2014, 美东)
I need to check the returned value from a stored procedure on SQL server
2008 R2.
import pyodbc
sql_str = """
DECLARE @return_value int
SET @return_value = -1
INSERT INTO [my_database].[dbo].[my_table]
EXEC @return_value = [my_database].[dbo].[my_stored_
procedure]
if @return_value <> 0
BEGIN
EXEC sys.sp_addmessage 60000, 16, ' test sp returns
wrong code ! '
RAISERROR (60000, 16, 1)
END
"""
sql_str_connect_db = " DRIVER={SQL server};SERVER={my_server};DATABASE={my_
db};UID=my_id;PWD=my_password "
cnxn = pyodbc.connect(sql_str_connect_db )
cursor_test = cnxn.cursor()
cursor_test.execute(sql_str)
cnxn_test.commit()
But, I got error:
pyodbc.Error: ('HY007', '[HY007] [Microsoft][ODBC SQL Server Driver]
Associated statement is not prepared (0) (SQLNumResultCols)')
And, how to check the value of "@return_value" in python ?
After searching , I cannot find a solution.
Thanks |
|