回 帖 发 新 帖 刷新版面

主题:时间段查询语句!

dim rs
dim sql
                        
                        
Fettle=request.form("Fettle")
txtitle=request.Form("txtitle")
Begintime=trim(request.Form("Begintime"))
Endtime=trim(request.Form("Endtime"))
                        
                        
if len(Begintime)=0 then
Begintime=year(now)&"-"& mm &"-01"
end if
if len(Endtime)=0 then
Endtime=thistoday
end if

set rs=server.createobject("adodb.recordset")
sql="select * from news where Title like '%"&request("txtitle")&"%' and Fettle like '%"&request("Fettle")&"%' and Infotime>='"&Begintime&"' and Infotime<='"&Endtime&"' order by NewsID asc"
rs.open sql,conn,1,1

if rs.eof and rs.bof then 
response.write "<br><br><p align='center'>对不起,没有您要查询的信息!</p>" 
else

....

end if



我这个地方到底哪写错了   为什么查询不到数据     如果去掉and Infotime>='"&Begintime&"' and Infotime<='"&Endtime&"'就可以查询到title和fettle的数据    就是查询不到时间的数据

回复列表 (共3个回复)

沙发

怎么没有人帮忙解决啊?

板凳

这里已经没有什么人气了,不要抱太大希望。我的问题已经半月了,也没有人帮忙看

3 楼

提示什么错误?

数据库用的是Access,还是SQL Server?

如果是SQL Server数据库,可以这样写

sql="select * from news where Title like '%"&request("txtitle")&"%' and Fettle like '%"&request("Fettle")&"%' and Infotime>='"&Begintime&"' and Infotime<='"&Endtime&"' order by NewsID asc"

如果是Access数据库,需要把单引号换成#

sql="select * from news where Title like '%"&request("txtitle")&"%' and Fettle like '%"&request("Fettle")&"%' and Infotime>=[color=FF0000]#[/color]"&Begintime&"[color=FF0000]#[/color] and Infotime<=[color=FF0000]#[/color]"&Endtime&"[color=FF0000]#[/color] order by NewsID asc"

我来回复

您尚未登录,请登录后再回复。点此登录或注册