Tsql SQL Server 2012使用存储过程将存储过程的返回值写入单元格

Tsql SQL Server 2012使用存储过程将存储过程的返回值写入单元格,tsql,stored-procedures,sql-server-2012,Tsql,Stored Procedures,Sql Server 2012,我在SQLServer2012中编写了一个存储过程,它接受三个输入值,并在进行一些计算后返回一个结果和 DECLARE @return_value int, @total numeric(20, 2) EXEC @return_value = [dbo].[storedprocedure] @input1 = 'input_value', @input2= 12345,

我在SQLServer2012中编写了一个存储过程,它接受三个输入值,并在进行一些计算后返回一个结果和

DECLARE @return_value int,
        @total numeric(20, 2)

EXEC @return_value = [dbo].[storedprocedure]
                        @input1 = 'input_value',
                        @input2= 12345,
                        @input3 = 5

SELECT @total as '@total'

SELECT 'Return Value' = @return_value
这将返回一个值,例如

@total 1000,02  --this is the correct value which I want to use--

我有一个表,其中一些列中的值用作输入,还有一个空列,我想将存储过程的@total变量的结果填入其中

如果我没有弄错的话,那么需要第二个存储过程来执行第一个存储过程,该存储过程在所有行中循环,并将值写入其中


执行此操作的最佳方法是什么?

我不知道存储过程中包含什么,但您可能可以创建一个函数。像这样:

CREATE FUNCTION [dbo].[YourFunctionName]
(
     @input1 VARCHAR(10)
    ,@input2 INT
    ,@input3 INT
)
RETURNS INT
AS
BEGIN
    -- Your code here.

    RETURN -- You return value here.
END
然后像这样使用它:

UPDATE YourTable
SET YourColumn = dbo.YourFunctionName(Input1, Input2, Input3)
否则,必须声明一个游标,执行存储过程并对每一行执行更新。由于几个原因,不建议使用迭代方法,但我想这超出了这个问题的范围

UPDATE YourTable
SET YourColumn = dbo.YourFunctionName(Input1, Input2, Input3)