注册 登录
编程论坛 ASP技术论坛

数据库内数据相加问题!

fujian567 发布于 2010-07-29 22:53, 1695 次点击
代码如下
<% Option Explicit %>
<!--#include file="config/conn.asp"-->
<%
on error resume next
dim rst,sql
set rst=server.createobject("adodb.recordset")
sql="select * from [xiaoshou] "
rst.open sql,conn,1,1
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<table width="90%" border="1" align="center" cellpadding="0" cellspacing="0"  bordercolor="#FFFFFF" bordercolorlight="#9CA6C6" bordercolordark="#CCE3FF">
 <tr bgcolor="#CCE3FF">
       <td  height="20" colspan="6"  >销售总额 :</td>
      </tr>
      <tr bgcolor="#CCE3FF">
        <td width="9%"  height="20" align="center" class="word_yellow">商品编号</td>
        <td width="9%" align="center" class="word_yellow">商品分类</td>
        <td width="8%" align="center" class="word_yellow">商品名称</td>
        <td width="8%" align="center" class="word_yellow">销售数量</td>
        <td width="15%" align="center" class="word_yellow">销售金额</td>
        <td width="36%" align="center" class="word_yellow">销售时间</td>
      </tr>
<%
do while not rst.eof
%>
      <tr bgcolor="#CCE3FF">
        <td align="center"><%=rst("x_bid")%></td>
        <td align="center"><%=rst("x_fname")%></td>
        <td align="center"><%=rst("x_name")%></td>
        <td align="center"><%=rst("x_num")%></td>
        <td align="center"><%=rst("x_price")%></td>
        <td align="center"><%=rst("x_time")%></td>
      </tr>
<%
rst.movenext
loop
%>
</table>
<%
rst.close
set rst=nothing
conn.close
set conn=nothing
%>
</body>
</html>
我向把数据库里的销售总额统计出来,我用SUM后总是出现脚本超时,还请各位大侠帮帮忙!

[ 本帖最后由 fujian567 于 2010-7-29 22:55 编辑 ]
4 回复
#2
gupiao1752010-07-30 02:38
SUM(字段),字段必须是数字型的,否则会出错,不能去统计全部字段的。除非你用SQL 2000的存储过程,全部放里头计算!
建议你把所有字段拿到ASP代码里相加,然后赋给一个变量,然后在需要显示的地方显示就是总和了。
#3
fujian5672010-07-30 15:59
版主能说的具体吗?如何把所有要相加的字段放在ASP代码里相加?
#4
gupiao1752010-07-30 16:13
你查数据库,这里的代码用范例,到的时候你自己替换:
假设:SQL代码sql="select *  from table where id=333"执行这条后会得到你想要的各字段值

dim zonghe=rs(1)+rs(2)+rs(3)...'把需要的字段取出来相加即可!
response.write zonghe'这里就是要显示的地方
#5
fujian5672010-07-30 17:06
谢谢,问题终于解决了!
1