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

jiulis 2004-08-11 05:34:44
接收表单3个变量分别为request("aa"),request("bb"),request("cc")
模糊查询数据库中记录
select * from table where .............
求where后语句,三个字段分别为field1,field2,field3
...全文
135 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
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") 其中有为空的话,按照符合所有条件查询

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧