求一条ASP+ACCESS 的数据库查询语句,高分相送!!!!!!!!

jiulis 2004-08-11 05:34:44
接收表单3个变量分别为request("aa"),request("bb"),request("cc")
模糊查询数据库中记录
select * from table where .............
求where后语句,三个字段分别为field1,field2,field3
...全文
103 13 点赞 打赏 收藏 举报
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
MOTA 2004-08-11
都解完了

进来看看
  • 打赏
  • 举报
回复
cdsun 2004-08-11
sql="select * from table where id>0"
if trim(request("aa"))<>"" then
sql=sql + " and field1='"&trim(request("aa"))&"'"
end if
if trim(request("bb"))<>"" then
sql=sql + " and field2='"&trim(request("cc"))&"'"
end if
if trim(request("cc"))<>"" then
sql=sql + " and field3='"&trim(request("cc"))&"'"
end if
  • 打赏
  • 举报
回复
sheng9hhd 2004-08-11
select * from tablename where field1 like '%" & trim(request("aa")) & "%' or field2 like '%" & trim(request("bb")) & "%' or field3 like '%" & trim(request("cc")) & "%'
  • 打赏
  • 举报
回复
sheng9hhd 2004-08-11
select * from tablename where field1 like '%" & trim(request("aa")) & "%' or field2 like '%" & trim(request("bb")) & "%' or field3 like '%" & trim(request("cc")) & "%'
  • 打赏
  • 举报
回复
ycted 2004-08-11
先用if语句判断.判断完后在合并sql语句.代码上面很详细了.
  • 打赏
  • 举报
回复
zyddamon 2004-08-11
对先判断 根据不同的判断来执行不同的查询 也只有先判断 防止为空
  • 打赏
  • 举报
回复
dcwang 2004-08-11
function IsNot(InputString,StringType)
'默认输入不合法
IsNot = false
'输入为空时不合法
if Trim(InputString) = "" then exit function
'合法输入
select case StringType
case "n"
if IsNumeric(InputString) then IsNot = true
case "d"
if IsDate(InputString) then IsNot = true
case "s"
IsNot = true
case else
IsNot = false '不可知情况视为不合法
end select
end function


sql = "select * from data where id<>0 "
'搜索条件
if IsNot(name,"s") then sql = sql & " and data.name like '%" & name & "%'"

if IsNot(dq,"s") then sql = sql & " and data.dq like '%" & dq & "%'"
'response.write sql
if IsNot(sex,"s") then sql = sql & " and data.sex = '" & sex & "'"
if IsNot(vname,"s") then sql = sql & " and data.vname = '" & vname & "'"
if IsNot(jg,"s") then sql = sql & " and data.jg like '%" & jg & "%'"
if IsNot(kind,"s") then sql = sql & " and data.kind like '%" & kind & "%'"
if IsNot(xq,"s") then sql = sql & " and data.xq like '%" & xq & "%'"
if IsNot(c_date,"s") then sql = sql & " and data.c_date like '%" & c_date & "%'"
if IsNot(q_date,"d") then sql = sql & " and data.q_date like '%" & q_date & "%'"
if IsNot(j_date,"d") then sql = sql & " and data.j_date like '%" & j_date
  • 打赏
  • 举报
回复
boywind 2004-08-11
再加一些判断语句
sql="select * from table where id>0"
if trim(request("aa"))<>"" then sql=sql & " and field1='"&trim(request("aa"))&"'"
if trim(request("bb"))<>"" then sql=sql & " and field2='"&trim(request("cc"))&"'"
if trim(request("cc"))<>"" then sql=sql & " and field3='"&trim(request("cc"))&"'"
  • 打赏
  • 举报
回复
zhongmao 2004-08-11
sql = "select * from table where field1 like '%" & request("aa") & "%' and field2 like '%" & request("bb") & "%' and field3 like '%" & request("cc") & "%'"
  • 打赏
  • 举报
回复
beaner2004 2004-08-11
key1=request("aa")
key2=request("bb")
key3=request("cc")
select * from table where field1 like '%"&key1&"%' and field2 like '%"&key2&"%' and field3 like '%"&key3&"%'
  • 打赏
  • 举报
回复
boywind 2004-08-11
???什么意思?

与关系 sql="select * from table where field1='"&trim(request("aa"))&"' and field2='"&trim(request("aa"))&"' and field3='"&trim(request("aa"))&"'"

或关系 sql="select * from table where field1='"&trim(request("aa"))&"' or field2='"&trim(request("aa"))&"' or field3='"&trim(request("aa"))&"'"
  • 打赏
  • 举报
回复
aspgreener 2004-08-11
select *
from table
where field1 like %'&request("aa")&'% or
field2 like %'&request("bb")&'% or
field3 like %'&request("aa")&'%"
  • 打赏
  • 举报
回复
jiulis 2004-08-11
如果request("aa"),request("bb"),request("cc") 其中有为空的话,按照符合所有条件查询
  • 打赏
  • 举报
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2004-08-11 05:34
社区公告
暂无公告