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
select * from tablename where field1 like '%" & trim(request("aa")) & "%' or field2 like '%" & trim(request("bb")) & "%' or field3 like '%" & trim(request("cc")) & "%'
select * from tablename where field1 like '%" & trim(request("aa")) & "%' or field2 like '%" & trim(request("bb")) & "%' or field3 like '%" & trim(request("cc")) & "%'
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
再加一些判断语句
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"))&"'"
sql = "select * from table where field1 like '%" & request("aa") & "%' and field2 like '%" & request("bb") & "%' and field3 like '%" & request("cc") & "%'"
key1=request("aa")
key2=request("bb")
key3=request("cc")
select * from table where field1 like '%"&key1&"%' and field2 like '%"&key2&"%' and field3 like '%"&key3&"%'