sql-server-2008 - 设置@var = exec存储过程

标签 sql-server-2008 exec

是否可以在变量中分配从exec存储过程返回的值?

就像是

DECLARE @count int
SET @count = Execute dbo.usp_GetCount @Id=123

最佳答案

您可以使用sp_executesql代替exec分配给标量输出参数

DECLARE @out int

EXEC sp_executesql N'select @out_param=10',
                   N'@out_param int OUTPUT',
                     @out_param=@out OUTPUT

SELECT @out


对于exec我只知道如何使用表变量

declare @out table
(
out int
)

insert into @out
exec('select 10')

select * 
from @out


对于存储过程,您还可以使用output参数或返回码。后者只能返回一个整数,通常首选返回错误代码而不是数据。两种技术都在下面演示。

create proc #foo 
@out int output
as
set @out = 100
return 99

go

declare @out int, @return int

exec @return = #foo @out output

select @return as [@return], @out as [@out]

drop proc #foo

关于sql-server-2008 - 设置@var = exec存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5439005/

相关文章:

sql - 临时表列大小在多少行之后确定?

sql-server - 在 SQL 2008 中使用 Sequelize.js 进行分页(不支持 FETCH)

c - 从 execlp() 获取返回

sql-server-2008 - 结果窗口的默认大小 SQL Server Management Studio 或替代方案

sql-server-2008 - 更新阿拉伯语数据

c - 如何模拟进程运行?

bash - 有人可以解释这个 bash : “_ {}\;” 末尾符号的内部工作原理吗

linux - UNIX diff 命令在 puppet exec 上的使用

c++ - 如果父/子异常退出,则使 fork 进程保持事件状态 (C++)

.net - SQL 报告 - 多页 EMF 报告问题