如何同时取存储过程的返回值、输出参数及返回结果集
我举例说明我所遇到的问题如下所示:
有一个SQL Server 2000存储过程,其定义如下:
Create Proc FunctionA
@input1 int, @output1 int out
As
if @input1> 0
begin
set @output1=5
select StudentNo, StudentName from StudentInfo
return 0
end
else
begin
set @output=12
return 1
end
GO
我在ASP代码里面需要根据返回值进行判断,
如果返回值是0,那么可以去取结果集,并在页面显示输出参数output1和结果集;
如果返回值非0,只能显示输出参数,(结果集根本就不能去取,因为不存在)。
我的代码如下:
input1=1
Set MyComm = Server.CreateObject( "ADODB.Command ")
MyComm.ActiveConnection = conn
MyComm.CommandText = "FunctionA "
MyComm.CommandType = 4
MyComm.Prepared = true
MyComm.Parameters.Append MyComm.CreateParameter( "RETURN ",2,4)
MyComm.Parameters.append MyComm.CreateParameter( "@input1 ",3,1,4,input1)
MyComm.Parameters.append MyComm.CreateParameter( "@output1 ",3,2,4)
Set MyRst=MyComm.Execute
return=MyComm(0)
ReturnInfo=mycomm(3)
现在我遇到的问题是:执行这样的ASP代码,无法取得返回值,请问我要如何操作,才能取得返回值,并依据返回值判断是否取结果集。
------解决方案---------------------------------------------------------------
ASP怎么获得SQL语句和存储过程执行后的返回值呢?
-------------------------------------------
CREATE PROCEDURE [dbo].[test_out]
-- Add the parameters for the stored procedure here
@p0 nvarchar(5) = ' ' ,
@p1 nvarchar(50) = ' ' output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
declare @sql nvarchar(800)
SET NOCOUNT ON;
if (@p0 = '1 ')
begin
set @p1 = 'a '
end
else
begin
set @p1 = 'b '
end
-- Insert statements for procedure here
set @sql = 'SELECT * from test1 '
exec sp_executesql @sql
END
asp:
set cmd = server.CreateObject( "adodb.command ")
with cmd
.commandText = "test_out "
.commandtype = adCmdStoredProc
.activeconnection = conn
.parameters.Append .createparameter( "@p0 ",adVarChar,adParamInput,5)
.parameters.Append .createparameter( "@p1 ",adVarChar,adParamOutput,50)
.parameters( "@p0 ") = "1 "
set rs = .ex