急!!SQL存储过程在SQL SERVER中可以运行,并且结果正确,而在ASP中出现运行错误,请问这是为什么?

zhudaifu 2005-12-19 07:22:19
以下是存储过程的定义:

CREATE PROCEDURE proc_cust_query
@datesa datetime,
@datesato datetime,
@datefrom datetime,
@dateto datetime,
@clsno varchar(8)='%'
as

select sup_man,sup_name,
sale_money=sum(sale_money),
tui_money=sum(tui_money),
sa_salemoney=sum(sa_salemoney),
sale=sum(sale_money-tui_money),

profit=sum(profit)
into #a
from(

--查询数据源
--数据源表列
--从销售单中提取销售明细数据,按客户名称进行汇总
select sup_man=c.other3,sup_name=c.sup_name,
sa_salemoney=isnull(b.sale_money,0),
sale_money=0,
tui_money=0,
profit=0
from sm_t_salesheet a,sm_t_salesheet_detail b, bi_t_supcust_info c
where a.cust_no=c.supcust_no and b.sheet_no=a.sheet_no
and a.oper_date between @datesa and @datesato
and b.item_no like @clsno
and c.region_no in ('1015','1036','1040','1041')
and c.other3 is not NULL
and supcust_flag='C'

union all
select sup_man=c.other3,sup_name=c.sup_name,
sa_salemoney=isnull(-e.sub_amount,0),
sale_money=0,
tui_money=0,
profit=0
from ic_t_inout_store_master d,ic_t_inout_store_detail e, bi_t_supcust_info c
where d.supcust_no=c.supcust_no and d.sheet_no=e.sheet_no
and d.sheet_no like 'RI%'
and d.oper_date between @datesa and @datesato
and e.item_no like @clsno
and c.region_no in ('1015','1036','1040','1041')
and c.other3 is not NULL
and supcust_flag='C'

union all
select sup_man=c.other3,sup_name=c.sup_name,
sa_salemoney=0,
sale_money=isnull(b.sale_money,0),
tui_money=0,
profit=isnull(b.sale_money-b.sale_qnty*f.cost_price,0)
from sm_t_salesheet a,sm_t_salesheet_detail b, bi_t_supcust_info c, ic_t_branch_stock f
where a.cust_no=c.supcust_no and b.sheet_no=a.sheet_no
and b.item_no=f.item_no and f.branch_no='00'
and a.oper_date between @datefrom and @dateto
and b.item_no like @clsno
and c.region_no in ('1015','1036','1040','1041')
and c.other3 is not NULL
and supcust_flag='C'

union all
select sup_man=c.other3,sup_name=c.sup_name,
sa_salemoney=0,
sale_money=0,
tui_money= e.sub_amount,
profit=isnull((-1)*( e.sub_amount-e.in_qty*f.cost_price),0)
from ic_t_inout_store_master d,ic_t_inout_store_detail e, bi_t_supcust_info c, ic_t_branch_stock f
where d.supcust_no=c.supcust_no and d.sheet_no=e.sheet_no
and e.item_no=f.item_no and f.branch_no='00'
and d.sheet_no like 'RI%'
and d.oper_date between @datefrom and @dateto
and e.item_no like @clsno
and c.region_no in ('1015','1036','1040','1041')
and c.other3 is not NULL
and supcust_flag='C'
)h group by sup_man,sup_name
order by sup_man desc,sup_name

--增加小计合计栏
select qudao=a.other2,
sup_man=case
when grouping(a.sup_name)=0 and grouping(a.other3)=0 then a.other3
when grouping(a.sup_name)=1 and grouping(a.other3)=0 then ''
when grouping(a.other3)=1 and grouping(a.other2)=0 then a.other2+'合计'
when grouping(a.other2)=1 then 'A/B总计'
else '' end,
sup_name=case
when grouping(a.sup_name)=0 then a.sup_name
when grouping(a.sup_name)=1 and grouping(a.other3)=0 then a.other3+'小计'
else '' end,
sale_money=sum(isnull(b.sale_money,0)),
tui_money=sum(isnull(b.tui_money,0)),
sa_salemoney=sum(isnull(b.sa_salemoney,0)),
sale=sum(isnull(b.sale,0)),
profit=sum(isnull(b.profit,0))
into #b
from bi_t_supcust_info a
left join #a b
on a.sup_name=b.sup_name
where
a.region_no in ('1015','1036','1040','1041')
and a.other3 is not NULL
and a.supcust_flag='C'
group by a.other2,a.other3,a.sup_name with rollup
order by grouping(a.other2),a.other2,grouping(a.other3),a.other3 desc , grouping(a.sup_name),a.sup_name
--增加退货率,比上月增长率,毛利率
--如果去掉以下代码,并且以上代码的结果不加入到临时表b,则此存储过程在ASP中可以得到正确运行结---果
select sup_man,sup_name,
sale_money=round(sale_money,2),
tui_money=round(tui_money,2),
tuili=round(tui_money/sale_money,2),
sa_salemoney=round(sa_salemoney,2),
sale=round(sale,2),
zeili=round((sale-sa_salemoney)/sa_salemoney,2),
profit=round(profit,2),
profitli=round(profit/sale,2)
from #b
drop table #a
drop table #b

以下是ASP的内容
文件1:proc_cust_query.htm
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>销售汇总表(KA/B)</title>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="0" width="669" height="228">

<tr>
<td width="109" height="28"></td>
<td width="383" height="28" colspan="2"><font color="#0000FF">>>销售统计报表</font></td>
<td width="171"></td>
</tr>
<tr>
<td width="109" height="35"></td>
<td width="383" height="35" colspan="2"><font color="#0000FF">  >>销售汇总表</font></td>
<td width="171"></td>
</tr>

<tr>
<td width="109" height="165"></td>
<td width="113" height="165">



</td>
<td width="268">
<form action="proc_cust_query.asp" method="post" name="query">
<p>
<font color="#0000FF">
上期开始日期:</font><input name="prestart" type="text" size="12"><br><br>
<font color="#0000FF">
上期结束日期:</font><input name="prestop" type="text" size="12"><br><br>

<font color="#0000FF">
本期开始日期:</font><input name="startdate" type="text" size="12"><br><br>
<font color="#0000FF">
本期结束日期:</font><input name="stopdate" type="text" size="12"><br><br>
<font color="#0000FF">
类   别:</font><input name="clsname" type="text" size="12"><br><br>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>

</td>
<td width="171" height="165"></td>
</tr>
<tr>
<td width="109" height="133"></td>
<td width="113" height="133"></td>
<td width="268" height="133"></td>
<td width="171"></td>
</tr>


</table>

</body>

</html>

以下是proc_cust_query.asp的内容:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>
<%

Set myCmd=Server.createObject("ADODB.Command")
myCmd.ActiveConnection="DSN=kmjxc;UID=sa"
myCmd.CommandTimeout=0
myCmd.Commandtext="proc_cust_query "
redim p(4)
p(0)=CStr(request.form("prestart"))
p(1)=CStr(request.form("prestop"))
p(2)=CStr(request.form("startdate"))
p(3)=CStr(request.form("stopdate"))
p(4)=CStr(request.form("clsname") )&"%"
Set myRecordSet=myCmd.Execute( ,p)
howmanyfields=myRecordSet.fields.count-1

%>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#000000"><tr bgcolor="#ffffff">
<%
for i=0 to howmanyfields
%>
<td><b><%=myRecordSet(i).name%></b></b></td>
<% next %>

</tr>
<%
do while not myRecordSet.eof
%>
<tr bgcolor="#ffffff">
<%
for i=0 to howmanyfields
thisvalue=myRecordSet(i)
if isnull(thisvalue) then
thisvalue=" "
end if
%>
<td valign=top><%=thisvalue%> </td>
<% next%>
</tr>
<%
myRecordSet.MoveNext --本行为第50行
loop
%>
</table>
<%
myRecordSet.close
set myRecordSet=nothing

%>

</body>

</html>

以下是出现错误的代码:

技术信息(适用于支持人员)

错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
/ASPTest/proc_cust_query.asp, 第 50 行


浏览器类型:
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)

页:
POST 92 bytes to /ASPTest/proc_cust_query.asp

POST 数据:
prestart=2005-11-03&prestop=2005-11-18&startdate=2005-12-05&stopdate=2005-12-20&clsname=1301







...全文
143 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhudaifu 2005-12-20
  • 打赏
  • 举报
回复
我试过了,只要去掉以下代码,并且在上面的代码中,将增加合计栏那一段的代码中into #b去掉的话可以得到正正确的运行结果!!!!!!
--增加退货率,比上月增长率,毛利率
--如果去掉以下代码,并且以上代码的结果不加入到临时表b,则此存储过程在ASP中可以得到正确运行结---果
select sup_man,sup_name,
sale_money=round(sale_money,2),
tui_money=round(tui_money,2),
tuili=round(tui_money/sale_money,2),
sa_salemoney=round(sa_salemoney,2),
sale=round(sale,2),
zeili=round((sale-sa_salemoney)/sa_salemoney,2),
profit=round(profit,2),
profitli=round(profit/sale,2)
from #b
drop table #a

由此可见,并不是参数不正确的问题!!!只是如果去掉了这一段代码的话,就没有商品退货率,增长率,毛利率了!!!
请各位大虾再帮忙看看!!~~!!
PaPaCong 2005-12-20
  • 打赏
  • 举报
回复
是输入参数类型的问题,仔细检查一下asp文件中参数的类型是否和过程中的一致,131(奴meric)类型要改为3(int)
zhudaifu 2005-12-20
  • 打赏
  • 举报
回复
楼上是何意,有点不懂!!!
我的myRecordSet变量是Command执行得到的结果集,为什么还要加
Set myRecordSet=Server.createObject("ADODB.recordset")这一名呢?
并且我的存储过程如果去掉增加退货率,比上月增长率那一段程序并且前一段增加合计栏的那一段程序不放入到临时表B,而是直接输出的话,可以在下面我创建的ASP代码中运行,并且可以得到正确的结果显示!!!!
请问这是为什么???
急!!!!!!
有哪位大虾可以帮忙解决一下吗?!!!!
lonaerd 2005-12-19
  • 打赏
  • 举报
回复
Set myCmd=Server.createObject("ADODB.Command")
增加:

Set myRecordSet=Server.createObject("ADODB.recordset")

你的myRecordSet是RS对象,所以必须先创建

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧