I want to get both a return code and a result set back from a stored procedure in classic ASP.
CREATE PROCEDURE CheckEmployeeId
@EmployeeName nvarchar(255)
AS
BEGIN
SET NOCOUNT ON;
DECLARE
@Exists INT
, @RowCount Int = 0
, @ReturnValue Int = 1
SELECT EmployeeId FROM Employees WHERE Name = @EmployeeName
set @RowCount = @@ROWCOUNT
if (@RowCount <> 1)
BEGIN
SET @ReturnValue = 2
END
ELSE
BEGIN
SET @ReturnValue = 1
END
RETURN @ReturnValue
END
So in ASP I can do the following to get the return value
Set cmd = CreateObject("ADODB.Command")
with cmd
.ActiveConnection = cnnstr
.CommandType = adCmdStoredProc
.CommandText = "CheckEmployeeId"
.Parameters.Refresh
.Parameters("@EmployeeName") = EmployeeName
end with
cmd.Execute()
RetVal = cmd.Parameters("@RETURN_VALUE")
or this to get the result set.
Set cmd = CreateObject("ADODB.Command")
with cmd
.ActiveConnection = cnnstr
.CommandType = adCmdStoredProc
.CommandText = "CheckEmployeeId"
.Parameters.Refresh
.Parameters("@EmployeeName") = EmployeeName
Set rst = .Execute()
end with
Is there a way to get both?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…