当前位置:编程学习 > C#/ASP.NET >>

ASP取SQL数据后求和的问题

比如说这里:http://reachseasky.vicp.net/
账号add 密码123
进去后点"瑞迪协作厂账务检索 "..选择时间后确定
取sql数据后返回叶面..最右边的“结余”数据
需要求所有“结余”的总和。。如何实现?谢谢高手



代码如下:

<!--#include file="asp/opendb.asp"-->
<!--#include file="asp/bgsub.asp"-->

<%
oabusyname=request.cookies("oabusyname")
oabusyusername=request.cookies("oabusyusername")
oabusyuserdept=request.cookies("oabusyuserdept")
oabusyuserlevel=request.cookies("oabusyuserlevel")
cook_allow_see_cw=request.cookies("cook_allow_see_cw")
oabusyclient_name=request.cookies("oabusyclient_name")
oabusyclient_id=request.cookies("oabusyclient_id")
if oabusyusername="" then response.redirect "index.asp"
c_year_start=request.form("c_year")
c_month_start=request.form("c_month")
c_day_start=request.form("c_day")
c_year_end=request.form("c_year_1")
c_month_end=request.form("c_month_1")
c_day_end=request.form("c_day_1")
querystart=c_year_start+c_month_start+c_day_start
queryend=c_year_end+c_month_end+c_day_end

%>
  <%
set rs_product=server.createobject("adodb.recordset")

sql1="SELECT a.manufplan_no, a.comanufcontractno, b.product_id, a.productamount, b.PcDate,SUM(b.jhamount) AS jhamount, SUM(b.qdamount) AS qdamount, SUM(b.cyamount) AS cyamount,(SELECT SUM(fpamount) FROM qcrepartationdetail c WHERE c.comanufcontractno = a.comanufcontractno AND c.product_id = a.product_id AND c.pc_no = b.pc_no AND fpflag = '1' AND billstatus_flag <> '10' AND entry_flag = b.entry_flag) AS hgamount,isnull((SELECT SUM(fpamount) FROM qcrepartationdetail c WHERE c.comanufcontractno = a.comanufcontractno AND c.product_id = a.product_id AND c.pc_no = b.pc_no AND fpflag = '3' AND billstatus_flag <> '10' AND entry_flag = b.entry_flag),0) AS fpamount,isnull((SELECT SUM(fpamount) FROM qcrepartationdetail c WHERE c.comanufcontractno = a.comanufcontractno AND c.product_id = a.product_id AND c.pc_no = b.pc_no AND fpflag = '2' AND billstatus_flag <> '10' AND entry_flag = b.entry_flag),0) AS fgamount, productorgunitprice, b.productunitprice - b.productorgunitprice AS price,CASE b.entry_flag WHEN '1' THEN '加工入库' WHEN '2' THEN '未加工退坯' WHEN '3' THEN '返工入库' END AS flag,isnull((SELECT round(SUM(fpamount)*(b.productunitprice - b.productorgunitprice),0) FROM qcrepartationdetail c WHERE c.comanufcontractno = a.comanufcontractno AND c.product_id = a.product_id AND c.pc_no = b.pc_no AND fpflag = '1' AND billstatus_flag <> '10' AND entry_flag = b.entry_flag),0) as yingshou,isnull((SELECT round(SUM(fpamount)*productorgunitprice,0) FROM qcrepartationdetail c WHERE c.comanufcontractno = a.comanufcontractno AND c.product_id = a.product_id AND c.pc_no = b.pc_no AND fpflag = '3' AND billstatus_flag <> '10' AND entry_flag = b.entry_flag),0) as yingkou FROM (SELECT DISTINCT comanufcontractno, product_id, manufplan_no, productamount FROM CoManufContractDetail) a INNER JOIN Entrystoredetail b ON a.comanufcontractno = b.ComanufContractNo AND a.product_id = b.product_id WHERE (b.PcClient_id ='"&oabusyclient_id&"') AND (b.PcDate BETWEEN '"&querystart&"' AND '"&queryend&"') AND (b.billstatus_flag <> '10') GROUP BY a.manufplan_no, a.comanufcontractno, b.product_id, a.product_id,a.productamount, b.PcDate, b.Pc_no, b.productorgunitprice, b.productunitprice,b.entry_flag ORDER BY b.PcDate, a.manufplan_no, a.comanufcontractno, b.product_id"
rs_product.open sql1,conn,1,1
%> 
  
  <%
call bghead()
%>
  <%
call bgmid()
%>
  <table border=1 width=100%  bordercolorlight="#000000" bordercolordark="#FFFFFF">
  <tr bgcolor="#0099ff">
  </tr>
  <%while not rs_product.eof and not rs_product.bof%>
<tr bgcolor="#B5DB9C">
    <td align=left width="3%"><font color="#000000" size="2"><%=rs_product("manufplan_no")%></font></td>
<td align=left width="3%"><font color="#000000" size="2"><%=rs_product("CoManufContractNo")%></font></td>
    <td align=left width="3%"><font color="#000000" size="2"><%=rs_product("product_id")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("ProductAmount")%></font></td>
    <td align=right width="2%"><font color="#000000" size="2"><%=rs_product("PcDate")%></font></td>
    <td align=right width="1%"><font color="#000000" size="2"><%=rs_product("jhamount")%></font></td>
    <td align=right width="1%"><font color="#000000" size="2"><%=rs_product("qdamount")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("cyamount")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("hgamount")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("fpamount")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("fgamount")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("price")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("flag")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("yingshou")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("yingkou")%></font></td>
<td align=right width="1%"><font color="#000000" size="2"><%=rs_product("yingshou")-rs_product("yingkou")%></font></td>
  </tr>
  
<%
rs_product.movenext
wend
%>

</table>
<p> </p>

<p>
  <%
rs_product.Close()
Set rs_product = Nothing
%>
</p>
<form id="form1" name="form1" method="post" action="excel2.asp">
  <table align="center">
  <tr>
  <td>
  查询起始日期:
  </td>
  <td>
  <input name="qsrq" type="text" class="input_bian" size="12" maxlength="16" value="<%=querystart%>">
  </td>
   <td>
  查询结束日期:
  </td>
  <td>
  <input name="jsrq" type="text" class="input_bian" size="12" maxlength="16" value="<%=queryend%>">
  </td>
  </tr>
  <tr>
  <td>
  <input name="tijiao" type="submit" class="annui"  value="下载保存该EXCEL表">
  </td>
  </tr>
  </table>
  
  <label></label>
</form>
--------------------编程问答-------------------- 图例这里:/upload/20131228/erp.png

请教大虾 --------------------编程问答-------------------- 错了是 daa:123
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,