我想知道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
答案 0 :(得分:2)
MS SQL存储过程可以返回return value
- 这与输出参数不同。
上面的代码可让您访问此返回值。
有关更多信息,请参阅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
答案 1 :(得分:1)
这是从存储过程返回的值。
来自Using a Stored Procedure with Output Parameters
您的SQL Server存储过程 可以打电话是一个返回一个或 更多的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();
}
}
答案 2 :(得分:0)
我认为,返回值的参数名称可以是任何内容 如果存储过程返回值,则可以将其写为
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