有人可以解释一下参数 RETURN_VALUE 吗?

发布于 2024-08-29 04:19:13 字数 1185 浏览 5 评论 0原文

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

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

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

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

UTid = RetVal

SQL Server 存储过程:

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

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..

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

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

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

UTid = RetVal

SQL Server stored procedure:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

波浪屿的海角声 2024-09-05 04:19:13

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

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

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

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

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

以下代码会将 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

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

The code above gives you access to this return value.

See MSDN for more information (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:

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
隔岸观火 2024-09-05 04:19:13

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

来自使用带有输出参数的存储过程

您可以使用的 SQL Server 存储过程
可以调用返回 1 或
更多 OUT 参数,分别是
存储过程的参数
用于将数据返回到
调用应用程序。

从链接

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();
   }
}

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.

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();
   }
}
海夕 2024-09-05 04:19:13

我认为,返回值的参数名称可以是任何东西。
如果你的存储过程返回一个值,它可以写成

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文