[返回首页] - [索引页面] - [文章列表]

 

主题:一个存储过程,怎么样取得返回值?




-----过程开始-----
CREATE Proc mis_search
@begin datetime,
@end datetime,
@price_a as int=null output
as
select start_time,
end_time= (select isnull(min(start_time),a.end_time)
from mis_roomtype_price where start_time>a.start_time),
price_a,price_b,price_c,bb=identity(int,1,1) into #b
from mis_roomtype_price a where end_time>=@begin and start_time<=@end
select *,bb=identity(int,1,1) into #c from mis_roomtype_price where end_time>=@begin and start_time<=@end
------------------------------------------
delete from #b where end_time<@begin
update #b set start_time=(case when start_time<@begin then @begin else start_time end) where bb in(select min(bb) from #b)
update #b set end_time=case when #b.end_time>#c.End_time then #c.end_time else #b.end_time end
from #b inner join #c on #b.bb=#c.bb
----------------------------
update #b set start_time=a.end_time from #b inner join #b a on(#b.bb=a.bb+1)
select start_time,end_time,price_a,price_b,price_c from #b
--------------------------过程 結束--------------------------
GO

问题:
一般情况下:
set rs=server.createobject("adodb.recordset")
sql="select * from mis_roomtype_price where id=2"
rs.open sql,conn,1,3
if not rs.eof then
price_a=rs("price_a")
end if
然后就可以直接用变量price了
那上面那个存储过程怎么样返回??


回复人:myvicy(在线解决:你的问题我来解决(因为我不会骗人,所以我最恨别人骗我。))  一星(中级)  信誉:100      2005-3-17 17:13:53  得分:50

CREATE PROCEDURE order_tot_amt @o_id int,@p_tot int output AS
SELECT @p_tot = sum(Unitprice*Quantity)
FROM orderdetails
WHERE ordered=@o_id

例子说明:
该例子是建立一个简单的存储过程order_tot_amt,这个存储过程根据用户输入的定单ID号码(@o_id),由定单明细表(orderdetails)中计算该定单销售总额[单价(Unitprice)*数量(Quantity)],这一金额通过@p_tot这一参数输出给调用这一存储过程的程序

三、在SQL Server中执行存储过程

在SQL Server的查询分析器中,输入以下代码:
declare @tot_amt int
execute order_tot_amt 1,@tot_amt output
select @tot_amt

以上代码是执行order_tot_amt这一存储过程,以计算出定单编号为1的定单销售金额,我们定义@tot_amt为输出参数,用来承接我们所要的结果

四、在ASP中调用存储过程

<!-- 必须加载adovbs.inc文件,否则将出错 -->
<!--#include file="adovbs.inc"-->
<%
dim objCnn
dim objCmd
dim Rs
const o_id=112

'-----建立Connection对象----------
set objCnn=Server.CreateObject("Adodb.connection")
objCnn.Open "driver={sql server};server=localhost;uid=sa;pwd=cncanet;database=check;"
'-----建立Command对象-----------
set objCmd=Server.CreateObject("Adodb.Command")
objCmd.ActiveConnection=objCnn
objCmd.CommandText="order_tot_amt" '指定存储过程名称
objCmd.CommandType=adCmdStoredProc '其为Stored Procedure
'-----准备stored procedure 的参数-------
objCmd.Parameters.Append _
objCmd.CreateParameter("o_id",adInteger,adParamInput,,o_id)
objCmd.Parameters.Append _
objCmd.CreateParameter("p_tot",adBigInt,adParamOutput,,0)
'-----执行存储过程----------------------
objCmd.Execute

'-----输出参数以及处理结果--------------
for each parm in objCmd.Parameters
Response.Write parm.name &"="& trim(parm) &"<br/>"
next
%>


以上代码在Win2000+IIS5.0+SQL Server2000中通过

TOP
回复人:cnwhitewolf(白狼)  二级(初级)  信誉:100      2005-3-17 17:15:32  得分:50

dim cmd,rs
set cmd = server.createobject("adodb.command")
cmd.activeconnection="数据连接"
cmd.commandtype=4 ''说明这是一个存贮过程
cmd.commandtext="存贮过程名字"

set rs=cmd.execute()

如果是单纯的返回值可以是这样
cmd.Parameters("@返回值变量名").value
剩下的就和你检索纪录集一样了
比如rs("Start_time")
TOP
回复人:mymyal123(风之森)  五级(中级)  信誉:100      2005-3-17 17:30:50  得分:0

明天跟你答案
TOP
回复人:blow_jj(阿俊)  两星(中级)  信誉:100      2005-3-17 17:31:54  得分:0

http://search.csdn.net/Expert/topic/492/492915.xml?temp=.5890619
http://search.csdn.net/Expert/topic/497/497121.xml?temp=.9456598
TOP
回复人:xiaoyao888(赵逍遥)  二级(初级)  信誉:99      2005-3-17 17:34:08  得分:0

rs.Open "调用存储过程的SQL语句",conn
TOP
回复人:potter2002(自由鸟)  一级(初级)  信誉:100      2005-3-18 9:30:23  得分:0

有哪位可以按我写的存储过程写一下吗?非常感谢了
TOP
回复人:potter2002(自由鸟)  一级(初级)  信誉:100      2005-3-20 9:12:52  得分:0

或者提供一些资料看看也行...
实在郁闷极了
TOP
回复人:kiccleaf(凯晰叶子)  四级(中级)  信誉:100      2005-3-20 9:31:56  得分:0

set rs=conn.execute(sql)
rs("字段")
TOP
回复人:potter2002(自由鸟)  一级(初级)  信誉:100      2005-3-20 11:56:10  得分:0

这样可以吗?我前面有一个存储过程..您可以在本地测试一下的
TOP


该问题已经结贴 ,得分记录:myvicy(50)、cnwhitewolf(50)、