将 SP 返回值设置为 SQL Server 中的变量 [英] Set a SP return value to a variable in SQL Server

查看:29
本文介绍了将 SP 返回值设置为 SQL Server 中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 sproc,它返回带有文本的单行和单列,我需要将此文本设置为一个变量,例如:

I have a sproc that returns a single line and column with a text, I need to set this text to a variable, something like:

declare @bla varchar(100)
select @bla = sp_Name 9999, 99989999, 'A', 'S', null

当然,这段代码不起作用...

but of course, this code doesn't work...

谢谢!

推荐答案

如果您无法更改存储过程,另一种解决方案是定义一个临时表,并将结果插入其中

If you are unable to change the stored procedure, another solution would be to define a temporary table, and insert the results into that

DECLARE @Output VARCHAR(100)

CREATE TABLE #tmpTable
(
    OutputValue VARCHAR(100)
)
INSERT INTO #tmpTable (OutputValue)
EXEC dbo.sp_name 9999, 99989999, 'A', 'S', null

SELECT
    @Output = OutputValue
FROM 
    #tmpTable

DROP TABLE #tmpTable

这篇关于将 SP 返回值设置为 SQL Server 中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆