ASP查询问题--在线等!

来源:百度知道 编辑:UC知道 时间:2024/05/05 13:50:00
有表a
表a中有字段id(自动id),name(文本型),num(文本型)
id name num
1 111 20
2 111 40
现在获取三个从表单提交过来的值:
a=request.form("aaa")
b=request.form("bbb")
c=request.form("ccc")
现在有这样一个查询:
Select * from a where name='"&a&"' and num>'"&b&"' and num<'"&c&"'"
问题是:
当我a,b,c都输入值时,一切正常
但是现在我只输入a
b,c为空,现在查询却查询不到任何记录.我想这样也可以查到记录,意思就是忽略后面两个条件.
求高手指教,如何实现我现在这个功能?
一楼的,你的回答是错误的.原因我就不说了,懂asp的人都知道
谢谢二楼三楼,你们的答案是正确的,但是我想让一句查询实现所有功能,不想用if语句.
四楼的如果此时b,c为空,那么cint(b)难道不会报错?

不能这样,b、c为空,SQL语句就变成这样:
Select * from a where name='"&a&"' and num>'' and num<''
显然是不对的。
应该这么改一下:
if b<>"" and c<>"" then
sql="Select * from a where name='"&a&"' and num>'"&b&"' and num<'"&c&"'"
elseif b<>"" then
sql="Select * from a where name='"&a&"' and num>'"&b&"'"
elseif c<>"" then
sql="Select * from a where name='"&a&"' and num<'"&c&"'"
else
sql="Select * from a where name='"&a&"'"
end if

做个判断只有当b或者c不为空时才加上and 后的条件,即当b不为空时加上and num>'"&b&"' 当c不为空时加上and num<'"&c&"' 当b和c都不为空时加上and num>'"&b&"' and num<'"&c&"'

你不用"AND"连接 把AN