还是一个年月查询问题。还是在线等

wangkp_kp 2005-04-28 11:52:22
用了两个下拉菜单分别表示年和月,数据库中的字段名是datetime类型的
<select name="year" id="year">
<option>全部</option>
<option>2005</option>
...................
<option>2002</option>
</select>
<select name="month" id="month">
<option>全部</option>
<option>1</option>
...................
<option>12</option>
</select>

怎么才能实现:当选择年只能查询年,选择月只能查出月,年月都选择的时候会查询符合年月的数值。。。帮个忙吧。。。
...全文
99 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangkp_kp 2005-04-28
  • 打赏
  • 举报
回复
<%

startmonth=request.form("year")&"-"&request.form("month")&"-1"
endmonth=dateadd(m,1,startmonth)
endmonth=dateadd(d,-1,endmonth)
set rs=Server.CreateObject("adodb.recordset")
sql="select * from zjgl_rszkb where d_cjsj between '"&startmonth&"' and '"&endmonth&"'"
rs.open sql,conn,1,1
%>

有人这样说,但是调试不通过阿
baiyunfei 2005-04-28
  • 打赏
  • 举报
回复
<%
sql="select * from table1 where 1=1 "
if request("Year")<>"" then
sql=sql & " and Year(datafield)=" & request("year")
end if
if request("month") <>"" then
sql=sql & " and Month(datafield)=" & request("month")
end if
........
%>

28,406

社区成员

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

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