求教 asp时间段查询

error911 2011-12-14 11:12:09
<!--#include file="inc/right.asp"-->
<!--#include file="inc/conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=sysConfig%></title>
<link href="images/main.css" rel="stylesheet" type="text/css">
</head>
<body>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td bgcolor="#FFFFFF">
<BR>
<table width="96%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#aec3de">
<tr align="center" bgcolor="#F2FDFF">
<td colspan="5" class="optiontitle">问卷调查统计</td>
</tr>

<%
dim startdate,enddate
startdate = request.form("startdate")
enddate = request.form("enddate")
set rstime = server.CreateObject("adodb.recordset")
sqltime = "select * from Result where datediff('d','" & startdate& "',addtime)>=0 and datediff('d','" &enddate&"',addtime)<=0"
rstime.open sqltime,conn,1,1
%>



<tr align="center" bgcolor="#F2FDFF">
<td colspan="5">
<form id="formtime" name="formtime" method="post" action="ResultTopictime.asp">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>
<td width="642" height="25" align="right" valign="middle">
起始日期:
<input name="startdate" type="text" id="startdate" size="15" value="2011-12-13"/>
截止日期:
<input name="enddate" type="text" id="enddate" size="15" value="2011-12-14"/></td>
<td width="432" align="left"><input type="submit" name="button" id="button" value="查询" /></td>
</tr>
</table>
</form>

</td>
</tr>


<%
sqlTotal="select count(id) as TotalNum from Result where datediff('d','" & startdate& "',addtime)>=0 and datediff('d','" &enddate&"',addtime)<=0"
set rsTotal=server.createobject("adodb.recordset")
rsTotal.open sqlTotal,conn,1,1
total=rsTotal("TotalNum")
if total=0 then '判断是否有问卷信息
%>
<tr>
<td colspan="5" bgcolor="#ffffff">目前还没有问卷信息提交!</td>
</tr>
<%
else '有问卷统计信息
rsTotal.close
set rsTotal=nothing
%>
<tr>
<td colspan="5" bgcolor="#ffffff" align="right">有效答卷:<%=total%> 份</td>
</tr>




<%
dim sqlInfo,rsInfo
sqlInfo="select * from Info "
Set rsInfo= Server.CreateObject("ADODB.Recordset")
rsInfo.open sqlInfo,conn,1,1
if rsInfo.eof then '判断是否有问卷信息
response.Write("<tr align='center' bgcolor='#ffffff'><td colspan='8'>还没有问卷信息,请先添加问卷信息。</td></tr>")
else '有问卷信息
For i = 1 to rsInfo.recordcount
Cha="topic"&i
%>
<tr bgcolor="#ebf0f7">
<td colspan="5" class="title"><%=i%>、<%=rsInfo("Topic")%></td>
</tr>
<%for n=1 to rsInfo("TCount")%>
<%if rsInfo("Option"&n) <>"" then%>
<tr bgcolor="#ffffff" onmouseover='this.style.background="#F2FDFF"' onmouseout='this.style.background="#FFFFFF"'>
<td width="40%"><%=rsInfo("Option"&n)%></td>
<td>
<%
res="·"&rsInfo("Option"&n)&"√"
sql="select count("&Cha&") as sum from Result where "&Cha&" like '%"&res&"%'"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
%>
<font color="#ff0000"><%=rs("sum")%></font>票 (<%=FormatPercent(rs("sum")/total)%>)</td>
<td width="45%"><img src="images/vote.jpg" width=<%=rs("sum")%> height=10></td>
</tr>
<%end if%>
<%next%>







<%
rsInfo.movenext
next'逐一查询结束
rsInfo.close
set rsInfo=nothing
rs.close
set rs=nothing
end if
end if
%>





<%
rstime.movenext
rstime.close
set sqltime=nothing
%>

</table>
</td>
</tr>
</table>
<br>
</body>
</html>


这样写对吗?
...全文
141 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmrxw 2011-12-16
  • 打赏
  • 举报
回复
datediff(day,'" & startdate& "',addtime)这个才是SQL语句正常写法!

datediff('d','" & startdate& "',addtime)这个写法是ASP代码写法!
csdn_aspnet 2011-12-15
  • 打赏
  • 举报
回复
sqlserver查询一段时间:
select * from rzgl where rq>='2011-11-28' and rq<='2011-11-30'
查询六天内信息:
select * from shop_news where datediff(dd,adddate,getdate())<=6 order by adddate desc
ldawrc 2011-12-15
  • 打赏
  • 举报
回复
天 怎么全挤到前台来了。你就不能写到存储过程去再写到后台判断么。
三石-gary 2011-12-15
  • 打赏
  • 举报
回复
首先你不用问写的对不对。。。你直接运行下。。就知道对不对了
error911 2011-12-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ldawrc 的回复:]
天 怎么全挤到前台来了。你就不能写到存储过程去再写到后台判断么。
[/Quote]
我全贴上来而已

28,391

社区成员

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

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