数据库提交查询如何实现满足全部条件?谢谢 area=trim(request("area")) sql="select * from user where area='"&area&" area是从前面一个表提交的,比如area在数据库里面是浦东,浦西(两个),我在前面一个表里面的表单选项有浦东,浦西,全部。 浦东和浦西都能反馈出来,但是如果我要全部(包括浦东和浦西)的where的表达式该如何写呢或者前面可以做哪些判断? 谢谢各位
其实你可以换种方式
想想,查询全部,就相当于没条件,
我们可以假如初始化时
area=trim(request("area"))
strSQL="select * from [user] where 1=1 "
这个条件永远成立,然后再
if area<>"" then strSQL=strSQL & " and area='" & area & "'"
[Quote=引用 11 楼 luxu001207 的回复:]
......
if area="全部" then
whereStr=" where area='浦东' and area='浦西' "
else
whereStr=" where area='"&area&"'"
end if
...
sql="select * from user "&whereStr
[/Quote]
谢谢,实现了,纠正一下,是whereStr=" where area='浦东' or area='浦西' "
......
if area="全部" then
whereStr=" where area='浦东' and area='浦西' "
else
whereStr=" where area='"&area&"'"
end if
...
sql="select * from user "&whereStr
[Quote=引用 7 楼 luxu001207 的回复:]
晕...
那就加个判断啊,要不用instr来写sql语句
if area="全部" then
...
else
...
end if
[/Quote]
这个我当然想到了,问题是if area="全部" then area=什么呢,很明显where area='"&area&" 是要求表单内容的,你明白吗?我想我思路很清楚,就好比,area='"&area&" ('"&area&" 反馈了前面表单的内容,如果表单是浦东,那么area=“浦东”),但是如果是全部呢?很明显如果if area=“全部” then then area=×? 很明显×是不行的,明白吗?