请高手指教如何使用asp语句实现一段时间范围内的ACCESS数据库数据的统计功能
我通过一个页面输入自己想要查询的时间段,然后数据库按照这个时间段查询满足要求的数据,然后把数量和价值计算总数,忘高手指教。我的代码如下:时间段输入页面<formname=...
我通过一个页面输入自己想要查询的时间段,然后数据库按照这个时间段查询满足要求的数据,然后把数量和价值计算总数,忘高手指教。
我的代码如下:
时间段输入页面
<form name="form1" method="post" action="tjbb2.asp">
<tr>
<td>开始日期:</td>
<td>
<select name="year1">
<%for i=2003 to 2100%>
<option value="<%=i%>" <%if year(now())=i then%>selected<%end if%>><%=i%></option>
<%next%>
</select>
年
<select name="month1">
<%for i=1 to 12%>
<option value="<%=i%>" <%if year(date())=i then %>selected<% end if %>><%=i%></option>
<%next%>
</select>
月
<select name="day1">
<%for i=1 to 31%>
<option value="<%=i%>" ><%=i%></option>
<%next%>
</select>
日 </td>
</tr>
<tr>
<td width="70">结束日期:</td>
<td width="278">
<select name="year2">
<%for i=2004 to 2100%>
<option value="<%=i%>" ><%=i%> </option>
<%next%>
</select>
年
<select name="month2">
<%for i=1 to 12%>
<option value=<%=i%> ><%=i%> </option>
<%next%>
</select>
月
<select name="day2">
<%for i=1 to 31%>
<option value=<%=i%> <%if year(date())=i then%>selected<%end if%>><%=i%> </option>
<%next%>
</select>
日 </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="查看">
</td>
</tr>
</form>
数据提取页面
下面这个是获取上面页面选定的时间范围
'day1=trim(Request.Form("year1"))&"-"&trim(Request.Form("month1"))&"-"&trim(Request.Form("day1"))
'day2=trim(Request.Form("year2"))&"-"&trim(Request.Form("month2"))&"-"&trim(Request.Form("day2"))
day1="#"&trim(Request.Form("month1"))&"-"&trim(Request.Form("day1"))&"-"&trim(Request.Form("year1"))&"#"
day2="#"&trim(Request.Form("month2"))&"-"&trim(Request.Form("day2"))&"-"&trim(Request.Form("year2"))&"#"
数据查询语句,查询统计表中的数量和价值
z_xs_sl=0
z_xs_je=0
while not rs.eof
set rs2=server.createobject("adodb.recordset")
rs2.open "select * from shop_action where (datediff('d',fhsj,"&day2&")>=0) and (datediff('d',"&day1&",fhsj)>=0) and (bookid="&rs("bookid")&")",conn,1,1
'rs2.open "select * from shop_action where (datediff('d',fhsj,"&day2&")>=0) and (bookid="&rs("bookid")&")",conn,1,1
'response.write "select * from shop_action where datediff('d',fhsj,"&day2&")>=0 and datediff('d',"&day1&",fhsj)<=0 and bookid="&rs("bookid")
'response.end
xs_sl=0
xs_je=0
while not rs2.eof
xs_sl=xs_sl+rs2("bookcount")
xs_je=xs_je+rs2("zonger")
rs2.movenext
wend
rs2.close
set rs2=nothing
这个是页面显示数据代码
<td align="center" width="14%" bgcolor="#D9E6FF"><%=xs_sl%></td>
<td align="center" width="17%"><%=xs_je%></td>
但是上面的查询结果却显示数量为0、价值也为0,但是表shop_action中有数据,不知道怎么弄,忘高手指点,谢谢
在这个页面有其他的显示数据,比如名称、编号等都有,就是后面的数量、价值都为0。 展开
我的代码如下:
时间段输入页面
<form name="form1" method="post" action="tjbb2.asp">
<tr>
<td>开始日期:</td>
<td>
<select name="year1">
<%for i=2003 to 2100%>
<option value="<%=i%>" <%if year(now())=i then%>selected<%end if%>><%=i%></option>
<%next%>
</select>
年
<select name="month1">
<%for i=1 to 12%>
<option value="<%=i%>" <%if year(date())=i then %>selected<% end if %>><%=i%></option>
<%next%>
</select>
月
<select name="day1">
<%for i=1 to 31%>
<option value="<%=i%>" ><%=i%></option>
<%next%>
</select>
日 </td>
</tr>
<tr>
<td width="70">结束日期:</td>
<td width="278">
<select name="year2">
<%for i=2004 to 2100%>
<option value="<%=i%>" ><%=i%> </option>
<%next%>
</select>
年
<select name="month2">
<%for i=1 to 12%>
<option value=<%=i%> ><%=i%> </option>
<%next%>
</select>
月
<select name="day2">
<%for i=1 to 31%>
<option value=<%=i%> <%if year(date())=i then%>selected<%end if%>><%=i%> </option>
<%next%>
</select>
日 </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="查看">
</td>
</tr>
</form>
数据提取页面
下面这个是获取上面页面选定的时间范围
'day1=trim(Request.Form("year1"))&"-"&trim(Request.Form("month1"))&"-"&trim(Request.Form("day1"))
'day2=trim(Request.Form("year2"))&"-"&trim(Request.Form("month2"))&"-"&trim(Request.Form("day2"))
day1="#"&trim(Request.Form("month1"))&"-"&trim(Request.Form("day1"))&"-"&trim(Request.Form("year1"))&"#"
day2="#"&trim(Request.Form("month2"))&"-"&trim(Request.Form("day2"))&"-"&trim(Request.Form("year2"))&"#"
数据查询语句,查询统计表中的数量和价值
z_xs_sl=0
z_xs_je=0
while not rs.eof
set rs2=server.createobject("adodb.recordset")
rs2.open "select * from shop_action where (datediff('d',fhsj,"&day2&")>=0) and (datediff('d',"&day1&",fhsj)>=0) and (bookid="&rs("bookid")&")",conn,1,1
'rs2.open "select * from shop_action where (datediff('d',fhsj,"&day2&")>=0) and (bookid="&rs("bookid")&")",conn,1,1
'response.write "select * from shop_action where datediff('d',fhsj,"&day2&")>=0 and datediff('d',"&day1&",fhsj)<=0 and bookid="&rs("bookid")
'response.end
xs_sl=0
xs_je=0
while not rs2.eof
xs_sl=xs_sl+rs2("bookcount")
xs_je=xs_je+rs2("zonger")
rs2.movenext
wend
rs2.close
set rs2=nothing
这个是页面显示数据代码
<td align="center" width="14%" bgcolor="#D9E6FF"><%=xs_sl%></td>
<td align="center" width="17%"><%=xs_je%></td>
但是上面的查询结果却显示数量为0、价值也为0,但是表shop_action中有数据,不知道怎么弄,忘高手指点,谢谢
在这个页面有其他的显示数据,比如名称、编号等都有,就是后面的数量、价值都为0。 展开
1个回答
展开全部
修改下SQL语句
select 名称,编号,sum(sl) as 数量,sum(je) as 金额
from shop_action
where
datediff('d',fhsj,"&day2&")>=0
and
datediff('d',"&day1&",fhsj)<=0
and
bookid="&rs("bookid")
group by 名称,编号
*说明
名称,编号,这些字段换成你数据表实际的字段名称
汇总就在语句里面实现,然后页面在循环输出即可
select 名称,编号,sum(sl) as 数量,sum(je) as 金额
from shop_action
where
datediff('d',fhsj,"&day2&")>=0
and
datediff('d',"&day1&",fhsj)<=0
and
bookid="&rs("bookid")
group by 名称,编号
*说明
名称,编号,这些字段换成你数据表实际的字段名称
汇总就在语句里面实现,然后页面在循环输出即可
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询