由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - get value returned by SQLstored procedure from python (转载)
相关主题
run SQL stored procedure from pythonSQL Server 2005 Exec( )
DSN-less connection to SQL serverHow to merge tables in SQL Server 2000?
how to link to remote access database?一个sql问题:怎样实现 (((a1*10)+a2)*10+a3)*10 ... (转载)
create table on SQL server from python pyodbc (转载)SQL run a stored procedure by fetching from a cursor row by row
pypyodbc error access netezza SQL server on win7老印给我的一个Challenge
问一个db2的弱问题ORACLE Pro*C 远程接续一问?
[转载] 真的没有人懂 ORACLE pro*c阿? :((((Question about DSN (for oracle)
Question about T-SQL[转载] Hehe,不好意思,another question:)
相关话题的讨论汇总
话题: sql话题: value话题: server话题: my话题: procedure
进入Database版参与讨论
1 (共1页)
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
o**a
发帖数: 1315
2
make sure that procedure has an OUTPUT parameter
l******9
发帖数: 579
3
Yes, it has.
I can see it in SQL.
But, now, I need to see it from python.

【在 o**a 的大作中提到】
: make sure that procedure has an OUTPUT parameter
1 (共1页)
进入Database版参与讨论
相关主题
[转载] Hehe,不好意思,another question:)pypyodbc error access netezza SQL server on win7
Need help on finding dependency objects问一个db2的弱问题
question about import xml to sql table[转载] 真的没有人懂 ORACLE pro*c阿? :((((
请问sql server里面怎么输出变量到文本文件?Question about T-SQL
run SQL stored procedure from pythonSQL Server 2005 Exec( )
DSN-less connection to SQL serverHow to merge tables in SQL Server 2000?
how to link to remote access database?一个sql问题:怎样实现 (((a1*10)+a2)*10+a3)*10 ... (转载)
create table on SQL server from python pyodbc (转载)SQL run a stored procedure by fetching from a cursor row by row
相关话题的讨论汇总
话题: sql话题: value话题: server话题: my话题: procedure