有人可以解释我参数RETURN_VALUE吗?

时间:2022-11-30 22:48:24

I want to know what does RETURN_VALUE mean! I'm stuck at this thing. How to use RETURN_VALUE in a SQL Server stored procedure? thanks..

我想知道RETURN_VALUE是什么意思!我坚持这件事。如何在SQL Server存储过程中使用RETURN_VALUE?谢谢..

ASP:

ASP:

Set cmdDB = Server.CreateObject("ADODB.Command")
With cmdDB
   .ActiveConnection = ADOConM
   .CommandText = "usp_jaljava_member_select"
   .CommandType = adCmdStoredProc
   .Parameters.Append .CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue, 0)
   .Parameters.Append .CreateParameter("@TLoginName", adVarChar, adParamInput, 15, lcase(TLoginName))
   .Parameters.Append .CreateParameter("@TPassword", adVarChar, adParamInput, 20, TPassword)
   .Parameters.Append .CreateParameter("@retval", adVarChar, adParamOutput, 50)

' .Parameters.Append .CreateParameter("@TPinCode", adVarChar, adParamInput, 15,TPinCode) .Execute,,adExecuteNoRecords

'.Parameters.Append .CreateParameter(“@ TPinCode”,adVarChar,adParamInput,15,TPinCode).Execute ,, adExecuteNoRecords

   RetVal = .Parameters("@retval")
   Ret = Trim(.Parameters("RETURN_VALUE"))

   'Set .ActiveConnection = Nothing
End With
Set cmdDB = Nothing

UTid = RetVal

SQL Server stored procedure:

SQL Server存储过程:

CREATE PROCEDURE usp_jaljava_member_select 
   @TLoginName varchar(15),
   @TPassword varchar(20),
   @retval varchar(50) OUTPUT
   --@TPinCode varchar(15)
AS

3 个解决方案

#1


2  

A MS SQL stored procedure can return a return value - this is apart from output parameters.

MS SQL存储过程可以返回返回值 - 这与输出参数不同。

The code above gives you access to this return value.

上面的代码使您可以访问此返回值。

See MSDN for more information (RETURN (Transact-SQL)).

有关更多信息,请参阅MSDN(RETURN(Transact-SQL))。

So, for the following stored procedure:

因此,对于以下存储过程:

CREATE PROCEDURE checkstate @param varchar(11)
AS
   IF (SELECT StateProvince FROM Person.vAdditionalContactInfo WHERE ContactID = @param) = 'WA'
   RETURN 1
ELSE
   RETURN 2;
GO

The following code would set Ret to 1 or 2, depending on the passed in parameter and data:

以下代码将Ret设置为1或2,具体取决于传入的参数和数据:

Set cmdDB = Server.CreateObject("ADODB.Command")
With cmdDB
    .ActiveConnection = ADOConM
    .CommandText = "checkstate"
    .CommandType = adCmdStoredProc
    .Parameters.Append .CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue, 0)
    .Parameters.Append .CreateParameter("@param", adVarChar, adParamInput, 11, "Contact")

    .Execute,,adExecuteNoRecords

    Ret = Trim(.Parameters("RETURN_VALUE"))

End With
Set cmdDB = Nothing

#2


1  

This is the value that would be returned from the Stored procedure.

这是从存储过程返回的值。

From Using a Stored Procedure with Output Parameters

从使用存储过程和输出参数

A SQL Server stored procedure that you can call is one that returns one or more OUT parameters, which are parameters that the stored procedure uses to return data back to the calling application.

您可以调用的SQL Server存储过程是一个返回一个或多个OUT参数的参数,这些参数是存储过程用于将数据返回给调用应用程序的参数。

From the link

从链接

CREATE PROCEDURE GetImmediateManager
   @employeeID INT,
   @managerID INT OUTPUT
AS
BEGIN
   SELECT @managerID = ManagerID 
   FROM HumanResources.Employee 
   WHERE EmployeeID = @employeeID
END

public static void executeStoredProcedure(Connection con) {
   try {
      CallableStatement cstmt = con.prepareCall("{call dbo.GetImmediateManager(?, ?)}");
      cstmt.setInt(1, 5);
      cstmt.registerOutParameter(2, java.sql.Types.INTEGER);
      cstmt.execute();
      System.out.println("MANAGER ID: " + cstmt.getInt(2));
   }
   catch (Exception e) {
      e.printStackTrace();
   }
}

#3


0  

I think, the parameter name for return value could be anything.
If your stored procedure returns a value, it could be written as

我认为,返回值的参数名称可以是任何内容。如果存储过程返回一个值,则可以将其写为

CREATE PROCEDURE usp_jaljava_member_select 
@TLoginName varchar(15),
@TPassword varchar(20),
@retval varchar(50) OUTPUT
--@TPinCode varchar(15)
AS

BEGIN
declare @errorCodeInCaseOfAnError int

Return @errorCodeInCaseOfAnError
END

#1


2  

A MS SQL stored procedure can return a return value - this is apart from output parameters.

MS SQL存储过程可以返回返回值 - 这与输出参数不同。

The code above gives you access to this return value.

上面的代码使您可以访问此返回值。

See MSDN for more information (RETURN (Transact-SQL)).

有关更多信息,请参阅MSDN(RETURN(Transact-SQL))。

So, for the following stored procedure:

因此,对于以下存储过程:

CREATE PROCEDURE checkstate @param varchar(11)
AS
   IF (SELECT StateProvince FROM Person.vAdditionalContactInfo WHERE ContactID = @param) = 'WA'
   RETURN 1
ELSE
   RETURN 2;
GO

The following code would set Ret to 1 or 2, depending on the passed in parameter and data:

以下代码将Ret设置为1或2,具体取决于传入的参数和数据:

Set cmdDB = Server.CreateObject("ADODB.Command")
With cmdDB
    .ActiveConnection = ADOConM
    .CommandText = "checkstate"
    .CommandType = adCmdStoredProc
    .Parameters.Append .CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue, 0)
    .Parameters.Append .CreateParameter("@param", adVarChar, adParamInput, 11, "Contact")

    .Execute,,adExecuteNoRecords

    Ret = Trim(.Parameters("RETURN_VALUE"))

End With
Set cmdDB = Nothing

#2


1  

This is the value that would be returned from the Stored procedure.

这是从存储过程返回的值。

From Using a Stored Procedure with Output Parameters

从使用存储过程和输出参数

A SQL Server stored procedure that you can call is one that returns one or more OUT parameters, which are parameters that the stored procedure uses to return data back to the calling application.

您可以调用的SQL Server存储过程是一个返回一个或多个OUT参数的参数,这些参数是存储过程用于将数据返回给调用应用程序的参数。

From the link

从链接

CREATE PROCEDURE GetImmediateManager
   @employeeID INT,
   @managerID INT OUTPUT
AS
BEGIN
   SELECT @managerID = ManagerID 
   FROM HumanResources.Employee 
   WHERE EmployeeID = @employeeID
END

public static void executeStoredProcedure(Connection con) {
   try {
      CallableStatement cstmt = con.prepareCall("{call dbo.GetImmediateManager(?, ?)}");
      cstmt.setInt(1, 5);
      cstmt.registerOutParameter(2, java.sql.Types.INTEGER);
      cstmt.execute();
      System.out.println("MANAGER ID: " + cstmt.getInt(2));
   }
   catch (Exception e) {
      e.printStackTrace();
   }
}

#3


0  

I think, the parameter name for return value could be anything.
If your stored procedure returns a value, it could be written as

我认为,返回值的参数名称可以是任何内容。如果存储过程返回一个值,则可以将其写为

CREATE PROCEDURE usp_jaljava_member_select 
@TLoginName varchar(15),
@TPassword varchar(20),
@retval varchar(50) OUTPUT
--@TPinCode varchar(15)
AS

BEGIN
declare @errorCodeInCaseOfAnError int

Return @errorCodeInCaseOfAnError
END