table 总列结果缺少某些值

table Total column results missing certain values

当 运行 sql 服务器 2005 查询 asp.net 页面并尝试对值 table 底部的值求和时,我注意到总值省略了我用粗体标出的值,这些值对应于周末发生的小结果#。我不明白为什么这些值被遗漏了。我认为这是转换单位(int、dbl 等)中的舍入问题,并尝试在不同的转换之间进行更改,但没有成功

(我是初学者,继承了现有的代码,所以请假设我对任何回复知之甚少)。由于我无法附上输出的屏幕截图,因此我只复制了一列数据作为示例。感谢所有帮助,谢谢!

发货日期:发货人总数:

2015 年 2 月 2 日 249

2015 年 2 月 3 日 254

2015 年 2 月 4 日 255

2015 年 2 月 5 日 263

2015 年 2 月 6 日 209

2015 年 2 月 7 日 6

2015 年 2 月 9 日 322

2015 年 2 月 10 日 304

2015 年 2 月 11 日 270

2015 年 2 月 12 日 212

2015 年 2 月 13 日 205

2015 年 2 月 14 日 2

总数:2543

<%@ Language="VBScript" %>
<% Option Explicit %>
<%
 Response.Expires = 0

 dim D1
  D1 = Request.Form("D1")
 dim D2
  D2 = Request.Form("D2")


 dim DispResults
  DispResults = Request.Form("A")

 dim TotalShippers, TotalShipperLines, TotalQuantityShipped, TotalKitsShipped, IntlTotalShippers, IntlTotalShipperLines, IntlTotalQuantityShipped, IntlTotalKitsShipped, GrandTotalShippers, GrandTotalShipperLines, GrandTotalQuantityShipped, GrandTotalKitsShipped
 IF D1 = "" THEN
  D1 = Month(Date()) & "/" & "1" & "/" & Year(Date())
 ELSE
 END IF

 IF D2 = "" THEN
  D2 = Date
 ELSE
 END IF

 
%>
<html>

<head>
<title>Daily Shipping Log</title>
<style>
body  {
 font-family: Tahoma, Verdana, Arial;
 font-size: 16px;
}
select {
 font-family: Tahoma, Verdana, Arial;
 font-size: 16px;
}
</style>
</head>

<body onLoad="document.Search.D1.focus()">
<center>
<img src="logo.jpg" ALT="Daily Shipping Log">

<br>

<form action="default.asp" method="POST" name="Search">
<input type=hidden name="A" value="1">

<table>
 <tr>
  <td align="center" valign="top">
   <table>

    <tr>
     <td align="center" valign="bottom">
      Enter Starting Date:&nbsp;
     </td>
     <td align="center" valign="bottom">
      <input type="text" name="D1" size="24" value="">
     </td>
    </tr>
    <tr>
     <td align="center" valign="bottom">
      Enter Ending Date:&nbsp;
     </td>
     <td align="center" valign="bottom">
      <input type="text" name="D2" size="24" value="">
     </td>
    </tr>
    <tr>
     <td colspan=2 align="center" valign="bottom">
      <input type="submit" value="Generate Report">
     </td>
    </tr>
   </table>
  </td>
  <td align="center" valign="top">
   <table>
    <tr>
     <td align="center" valign="top" style="background-color:#FFFF99; font-size:10px;">
      <b>Note:</b><br><br>
      Date formats must be in the following manner:<br><br>
      <b>MM/DD/YY</b> if using a 2-digit Month and Day.<br>
      <b>M/D/YY</b> is using a 1-digit Month or Day.<br><br>
      Other date formats will not return any records.
     </td>
    </tr>
   </table>
  </td>
 </tr>
</table>

</form>

<br>
<%

IF D1 = "" THEN
ELSEIF DispResults = 1 THEN
 Response.Write "Data Reported is for Date Range:&nbsp;<b>" & D1 & "</b> to <b>" & D2 & "</b><br>"
 Response.Write "<hr color=""#65035A"" size=2 width=""100%"">"
 Response.Write "<table cellpadding=5 cellspacing=0 border=1 bordercolor=#666666>"
 Response.Write "<tr align=center>" 
 Response.Write "<td><b>Domestic:</b>"
 Response.Write "</td><td><b>International:</td></tr>"
 Response.Write "<tr align=center valign=top>"
 Response.Write "<tr align=center>"
 Response.Write "<td>"
 Response.Write "<table cellpadding=5>"
 Response.Write "<tr align=center valign=top>" 
 Response.Write "<td>"
 Response.Write "<b>Shipped Date:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Total Shippers:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Total Line Items Shipped:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Total Quantity Items Shipped:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Configured Kits Shipped:</b>"
 Response.Write "</td></tr>"


 dim oConn, oRS, oRS2
 Set oConn = Server.CreateObject("ADODB.Connection")
 oConn.Open """
 Set oRS = Server.CreateObject("ADODB.Recordset")
 Set oRS2 = Server.CreateObject("ADODB.Recordset")

 oRS.open "Select s.ShipDate, Count(distinct CASE when s.country='USA' then l.ShipmentNo end) as TotalShippers, " & _
   "count(case when s.country='USA' then convert(int,l.ShipmentLineNo) END) as TotalLinesShipped, " & _
   "sum(case when s.country='USA' then (l.TotalShippedQuantity) else 0 END) as TotalItemsShipped, " & _
   "Count(distinct CASE when s.country<>'USA' then l.ShipmentNo end) as IntlTotalShippers, " & _
   "count(case when s.country<>'USA' then convert(int,l.ShipmentLineNo) END) as IntlTotalLinesShipped, " & _
   "sum(case when s.country<>'USA' then (l.TotalShippedQuantity) END) as IntlTotalItemsShipped, " & _
   "Count(distinct l.ShipmentNo) as GrandTotalShippers, " & _
   "convert(int, count(l.ShipmentLineNo)) as GrandTotalLinesShipped, " & _
   "sum(l.TotalShippedQuantity) as GrandTotalItemsShipped " & _
   "From shipments s, shipments_li l " & _
   "Where (s.ShipDate between '" & D1 & "' AND '" & D2 & "') " & _
   "and  s.ShipmentNo = l.ShipmentNo " & _
   "and l.TotalShippedQuantity>0 and s.status<>'X' AND " & _
   "s.shipfrominventory not in ('BI','CI','CS','IT')" & _
   " Group by s.ShipDate order by s.ShipDate", oConn
 
 
 DO WHILE NOT oRS.EOF
 Response.Write "<tr align=center><td>" & oRS("ShipDate") & "</td>"
 Response.Write "<td>" & oRS("TotalShippers").value & "</td>"
 Response.Write "<td>" & oRS("TotalLinesShipped").value & "</td>"
 Response.Write "<td>" & oRS("TotalItemsShipped").value & "</td>"
 
 oRS2.open "SELECT s.ShipDate, count(case when s.country='USA' THEN (l.ShipmentLineNo) end) AS CountOfKits, " & _
    "count(case when s.country<>'USA' THEN (l.ShipmentLineNo) end) AS IntlCountOfKits, " & _ 
           "count(l.ShipmentLineNo) AS GrandTotalCountOfKits " & _
    "FROM (shipments s INNER JOIN shipments_li l ON s.ShipmentNo = l.ShipmentNo) " & _
    "WHERE (l.TotalShippedQuantity>0) AND (s.Status<>'x') " & _
    "AND s.ShipDate='" & oRS("ShipDate").Value & "' " & _
    "AND (Left(l.partNo,5)<>'hires') AND (l.PartDescription<>'CHARGER KIT, AURIA') " & _
    "AND (Left(l.partNo,8) NOT IN ('303-M220' , '303-M218','303-M219')) " & _
    "AND (Left(l.partNo,4)<>'zeni') AND (Left(l.partNo,2)<>'sw') and (Left(l.partNo,7)<>'sr3upus')" & _ 
    "and l.Configuration is not null AND  s.shipfrominventory not in ('BI','CI','CS','IT')" & _
    "GROUP BY s.ShipDate " & _
    "ORDER By s.ShipDate", oConn

IF oRS2.EOF THEN Response.Write "<td>" & 0 & "</td></tr>" ELSE 
DO WHILE NOT oRS2.EOF
 Response.Write "<td>" & oRS2("CountOfKits").Value & "</td></tr>"
 TotalKitsShipped = CInt(oRS2("CountofKits").Value) + TotalKitsShipped
  
 TotalShippers = CInt(oRS("TotalShippers").Value) + TotalShippers
 TotalShipperLines = CInt(oRS("TotalLinesShipped").Value) + TotalShipperLines
 TotalQuantityShipped = CInt(oRS("TotalItemsShipped").Value) + TotalQuantityShipped
  

 oRS2.MoveNext
 Loop
 oRS2.Close

 oRS.MoveNext
 Loop
 oRS.Close

 Set oRS2 = Nothing   
 Set oRS = Nothing
 oConn.Close
 Set oConn = Nothing 

 Response.Write "<tr align=center><td><b>Totals:</b></td>"
 Response.Write "<td><b>" & TotalShippers & "</b></td>"
 Response.Write "<td><b>" & TotalShipperLines & "</b></td>"
 Response.Write "<td><b>" & TotalQuantityShipped & "</b></td>"
 Response.Write "<td><b>" & TotalKitsShipped & "</b></td></tr>"
 Response.Write "</td>"
 Response.Write "</tr>"
 Response.Write "</table>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<table cellpadding=5>"
 Response.Write "<tr align=center>" 
 Response.Write "<td>"
 Response.Write "<b>Total Shippers:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Total Line Items Shipped:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Total Quantity Items Shipped:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Configured Kits Shipped:</b>"
 Response.Write "</td></tr>"
Set oConn = Server.CreateObject("ADODB.Connection")
 oConn.Open "Driver={SQL Server}; Server=ABSQL21; Database=DF_WHSE; Uid=ReadOnlyUser; Pwd=bionics;"
 Set oRS = Server.CreateObject("ADODB.Recordset")
 Set oRS2 = Server.CreateObject("ADODB.Recordset")

 oRS.open "Select s.ShipDate, Count(distinct CASE when s.country='USA' then l.ShipmentNo end) as TotalShippers, " & _
   "count(case when s.country='USA' then convert(int,l.ShipmentLineNo) END) as TotalLinesShipped, " & _
   "sum(case when s.country='USA' then (l.TotalShippedQuantity) END) as TotalItemsShipped, " & _
   "Count(distinct CASE when s.country<>'USA' then l.ShipmentNo end) as IntlTotalShippers, " & _
   "count(case when s.country<>'USA' then convert(int,l.ShipmentLineNo) END) as IntlTotalLinesShipped, " & _
   "sum(case when s.country<>'USA' then (l.TotalShippedQuantity) else 0 END) as IntlTotalItemsShipped " & _
   "From shipments s, shipments_li l " & _
   "Where (s.ShipDate between '" & D1 & "' AND '" & D2 & "') " & _
   "and  s.ShipmentNo = l.ShipmentNo " & _
   "and l.TotalShippedQuantity>0 and s.status<>'X' AND " & _
   "s.shipfrominventory not in ('BI','CI','CS','IT')" & _
   "Group by s.ShipDate order by s.ShipDate", oConn
 
 
 DO WHILE NOT oRS.EOF
 Response.Write "<tr align=center>"
 Response.Write "<td>" & oRS("IntlTotalShippers").value & "</td>"
 Response.Write "<td>" & oRS("IntlTotalLinesShipped").value & "</td>"
 Response.Write "<td>" & oRS("IntlTotalItemsShipped").value & "</td>"

 oRS2.open "SELECT s.ShipDate, count(case when s.country='USA' THEN (l.ShipmentLineNo) end) AS CountOfKits, " & _
    "count(case when s.country<>'USA' THEN (l.ShipmentLineNo) end) AS IntlCountOfKits " & _
    "FROM (shipments s INNER JOIN shipments_li l ON s.ShipmentNo = l.ShipmentNo) " & _
    "WHERE (l.TotalShippedQuantity>0) AND (s.Status<>'x') " & _
    "AND s.ShipDate='" & oRS("ShipDate").Value & "' " & _
    "AND (Left(l.partNo,5)<>'hires') AND (l.PartDescription<>'CHARGER KIT, AURIA') " & _
    "AND (Left(l.partNo,8) NOT IN ('303-M220' , '303-M218','303-M219')) " & _
    "AND (Left(l.partNo,4)<>'zeni') AND (Left(l.partNo,2)<>'sw') and (Left(l.partNo,7)<>'sr3upus')" & _ 
    "and l.Configuration is not null AND  s.shipfrominventory not in ('BI','CI','CS','IT')" & _
    "GROUP BY s.ShipDate " & _
    "ORDER By s.ShipDate", oConn

IF oRS2.EOF THEN Response.Write "<td>" & 0 & "</td></tr>" ELSE 
DO WHILE NOT oRS2.EOF


 Response.Write "<td>" & oRS2("IntlCountOfKits").Value & "</td></tr>"
 IntlTotalKitsShipped = CInt(oRS2("IntlCountofKits").Value) + IntlTotalKitsShipped
 IntlTotalShippers = CInt(oRS("IntlTotalShippers").Value) + IntlTotalShippers
 IntlTotalShipperLines = CInt(oRS("IntlTotalLinesShipped").Value) + IntlTotalShipperLines
 IntlTotalQuantityShipped = CInt(oRS("IntlTotalItemsShipped").Value) + IntlTotalQuantityShipped
 GrandTotalShippers = TotalShippers + IntlTotalShippers
 GrandTotalShipperLines = TotalShipperLines + IntlTotalShipperLines
 GrandTotalQuantityShipped = TotalQuantityShipped + IntlTotalQuantityShipped
 GrandTotalKitsShipped = IntlTotalKitsShipped + TotalKitsShipped  

 oRS2.MoveNext
 Loop
 oRS2.Close

 oRS.MoveNext
 Loop
 oRS.Close
 Set oRS2 = Nothing   
 Set oRS = Nothing
 oConn.Close
 Set oConn = Nothing 
 Response.Write "<tr align=center>"
 Response.Write "<td><b>" & IntlTotalShippers & "</b></td>"
 Response.Write "<td><b>" & IntlTotalShipperLines & "</b></td>"
 Response.Write "<td><b>" & IntlTotalQuantityShipped & "</b></td>"
 Response.Write "<td><b>" & IntlTotalKitsShipped & "</b></td></tr>"
 Response.Write "</td></tr></table></td></tr>"
 Response.Write "<tr align=center><td colspan=2><table><tr align=center><td>"
 Response.Write "<b>Grand Total Shippers:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Grand Total Line Items Shipped:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Grand Total Quantity Items Shipped:</b>"
 Response.Write "</td>"
 Response.Write "<td>"
 Response.Write "<b>Grand Total Configured Kits Shipped:</b>"
 Response.Write "</td></tr>"
 Response.Write "<tr align=center>"
 Response.Write "<td><b>" & GrandTotalShippers & "</b></td>"
 Response.Write "<td><b>" & GrandTotalShipperLines & "</b></td>"
 Response.Write "<td><b>" & GrandTotalQuantityShipped & "</b></td>"
 Response.Write "<td><b>" & GrandTotalKitsShipped & "</b></td></tr>"
 Response.Write "</td></tr></table>"
ELSE
END IF
%>

</body>

</html>

我很好奇你是如何确定数字被排除在总数之外的,因为你已经承认对它的工作原理知之甚少。

跳出的一件事是该列上的 COUNT(DISTINCT)。每天进行汇总然后合计可能会比一次汇总整个集合得到更高的数字。我猜这就是问题所在。

作为第二个猜测,这段代码对我来说很奇怪。为什么它在 oRS2 上循环但重复从 oRS 中添加值?

DO WHILE NOT oRS2.EOF
    Response.Write "<td>" & oRS2("CountOfKits").Value & "</td></tr>"
    TotalKitsShipped = CInt(oRS2("CountofKits").Value) + TotalKitsShipped

    TotalShippers = CInt(oRS("TotalShippers").Value) + TotalShippers
    TotalShipperLines = CInt(oRS("TotalLinesShipped").Value) + TotalShipperLines
    TotalQuantityShipped = CInt(oRS("TotalItemsShipped").Value) + TotalQuantityShipped
    oRS2.MoveNext
LOOP