日期字段查询
<%
sql=""
ddate1=cdate(request("ddate1"))
ddate2=cdate(request("ddate2"))
sql = " select * from dhd where id is not null "
if ddate1 <>"" and ddate2 ="" then
sql= sql + " and (ddate = '" & ddate1 & "')"
end if
if ddate2 <>"" and ddate1 ="" then
sql= sql + " and (ddate = '" & ddate2 & "')"
end if
if ddate1 <>"" and ddate2 <>"" then
sql= sql + " and ( ddate >= '" & ddate1 & "')"
sql= sql + " and ( '" & ddate2 & "' >= ddate)"
end if
sql= sql + " order by id desc "
问题点数:20、回复次数:2Top
1 楼xuheguan(鄂鱼)回复于 2002-03-29 09:49:51 得分 0
后面的set rs=server.createobject("adodb.recordset")
conn = "DBQ=" + server.mappath("db1.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
rs.open sql,conn,1,1
rs.pagesize=MaxPerPage
出错rs.open sql,conn,1,1Top
2 楼beyond_xiruo(CorruptionException)回复于 2002-03-29 09:56:02 得分 20
sql语句错误,加上trim!
例外你必须注意的是,你的这个查询语句是在sql里的用法,在access里应该用“#”,改为以下的:
<%
sql=""
ddate1=cdate(request("ddate1"))
ddate2=cdate(request("ddate2"))
sql = " select * from dhd where id is not null "
if ddate1 <>"" and ddate2 ="" then
sql= sql + " and (ddate = #" & ddate1 & "#)"
end if
if ddate2 <>"" and ddate1 ="" then
sql= sql + " and (ddate = #" & ddate2 & "#)"
end if
if ddate1 <>"" and ddate2 <>"" then
sql= sql + " and ( ddate >= #" & ddate1 & "#)"
sql= sql + " and ( #" & ddate2 & "# >= ddate)"
end if
sql= sql + " order by id desc "
Top




