I have a SQL Server stored procedure; I need to capture the return value from the stored procedure. Is this the correct way of doing this?
我有一个SQL Server存储过程;我需要捕获存储过程的返回值。这是正确的做法吗?
declare valback varchar(30)
set valback = exec storeproc1
In this case, storeproc1
is my stored procedure.
在本例中,storeproc1是我的存储过程。
2 个解决方案
#1
34
To start, use proper T-SQL syntax:
首先,使用正确的T-SQL语法:
declare @valback int;
exec @valback = storeproc1;
The only return type allowed for a stored procedure is int
. Stored procedures return status via the return
statement.
存储过程允许的唯一返回类型是int.存储过程通过return语句返回状态。
I somehow have a feeling that you really want something else, namely: to have an OUTPUT parameter in the procedure:
我有一种感觉,你真的想要别的东西,即:在程序中有一个输出参数:
declare @valback varchar(30);
exec storedproc1 @valback OUTPUT;
or capture the procedure result set via INSERT ... EXEC
. See How to Share Data Between Stored Procedures.
或者通过INSERT…获取过程结果集。执行。了解如何在存储过程之间共享数据。
#2
1
The correct syntax is:
正确的语法是:
DECLARE @valback VARCHAR(30)
EXEC @valback = storeproc1
As per the documentation:
按照文档:
http://msdn.microsoft.com/en-us/library/ms188332.aspx
http://msdn.microsoft.com/en-us/library/ms188332.aspx
#1
34
To start, use proper T-SQL syntax:
首先,使用正确的T-SQL语法:
declare @valback int;
exec @valback = storeproc1;
The only return type allowed for a stored procedure is int
. Stored procedures return status via the return
statement.
存储过程允许的唯一返回类型是int.存储过程通过return语句返回状态。
I somehow have a feeling that you really want something else, namely: to have an OUTPUT parameter in the procedure:
我有一种感觉,你真的想要别的东西,即:在程序中有一个输出参数:
declare @valback varchar(30);
exec storedproc1 @valback OUTPUT;
or capture the procedure result set via INSERT ... EXEC
. See How to Share Data Between Stored Procedures.
或者通过INSERT…获取过程结果集。执行。了解如何在存储过程之间共享数据。
#2
1
The correct syntax is:
正确的语法是:
DECLARE @valback VARCHAR(30)
EXEC @valback = storeproc1
As per the documentation:
按照文档:
http://msdn.microsoft.com/en-us/library/ms188332.aspx
http://msdn.microsoft.com/en-us/library/ms188332.aspx