[英]SQL Server Stored Procedure capture return value in T-SQL
I have a SQL Server stored procedure; 我有一个SQL Server存储过程; I need to capture the return value from the stored procedure.
我需要从存储过程中捕获返回值。 Is this the correct way of doing this?
这是正确的做法吗?
declare valback varchar(30)
set valback = exec storeproc1
In this case, storeproc1
is my stored procedure. 在这种情况下,
storeproc1
是我的存储过程。
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
. 存储过程允许的唯一返回类型是
int
。 Stored procedures return status via the return
statement. 存储过程通过
return
语句返回状态。
I somehow have a feeling that you really want something else, namely: to have an OUTPUT parameter in the procedure: 我不知何故感觉你真的想要别的东西,即:在程序中有一个OUTPUT参数 :
declare @valback varchar(30);
exec storedproc1 @valback OUTPUT;
or capture the procedure result set via INSERT ... EXEC
. 或通过
INSERT ... EXEC
捕获过程结果集。 See How to Share Data Between Stored Procedures . 请参见如何在存储过程之间共享数据 。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.