0

I have a SP with an Output parameter that looks like: ALTER PROCEDURE [dbo].[SP_Name] @VarName decimal(18,2) OUTPUT as ...

I call that procedure from vb.net to get the value for calculations. My problem is: I have 8 SP's with the following structure:

CREATE PROCEDURE [dbo].[SP_Name] @VarName decimal(18,2) OUTPUT as ...
CREATE TABLE @TempTable
Begin
Select ...
End
SET @VarName = Result

But the TempTable is always the same. No I am looking for a way to get all 8 values with only one stored procedure. My idea:

CREATE PROCEDURE [dbo].[SP_Name] @VarName decimal(18,2) OUTPUT as ...
CREATE TABLE @TempTable
---Get first value
Begin
Select ...
End
SET @VarName1 = Result
---Get second value
Begin
Select ...
End
SET @VarName2 = Result
...

How do i have to rewrite the line: ALTER PROCEDURE [dbo].[SP_Name] @VarName decimal(18,2) OUTPUT ir can I even work with an array?

4

1 回答 1

1

您可以使用包含所有查询的单个存储过程。以下将返回包含八个字段的单行结果集,您可以使用特定的文件名或索引从代码中获取它们。

CREATE PROCEDURE [dbo].[SP_Name] 
  @VarName decimal(18,2) 
AS

BEGIN
    DECLARE @VarName1 Datatype, @VarName2 Datatype, ...@VarName8 Datatype

    SELECT @VarName1 = yourCol
    FROM --First query

    SELECT @VarName2 = yourCol
    FROM --Second query
    ...

    SELECT @VarName8 = yourCol
    FROM --Eighth query

    --Finally Select all the variables
    SELECT @VarName1 Col1, @VarName2 Col2, ...,@VarName8 Col8
END

或者,如果您希望返回所有 8 个查询的结果,这也是可能的。只需在单个存储过程中执行您的选择查询并DATASET从您的代码中获取,您就可以使用基于零的索引(例如DataTable1 = YourDataSet.Tables[0])访问单个表

于 2013-10-14T08:10:38.140 回答