dim sql
dim rs
sql="select * from [tablename] where 1=1"
if request("id")<>"" and isnumberic(request("id")) then
sql=sql & " and 编号=" & request("id")
else
if request("date")<>"" then sql=sql & " and 日期='" & replace(request("date"),"'","''") & "'"
if request("user")<>"" then sql=sql & " and 录入员='" & replace(request("user"),"'","''") & "'"
end if
response.write sql
set rs=conn.execute sql
search.asp 假设数据库链接文件为conn.asp
<!--#include file="conn.asp"-->
<%
keyword=request("keyword")
dizhi=request("dizhi")
if keyword="" then
response.write "<script language='javascript'>alert('关键字不能为空!');history.go(-1);<script>"
end if
set rs=Server.CreateObject("adodb.recordset")
if dizhi="" then
sql ="select * from [table] where chanpin like '%" & keyword & "%'"
else
sql ="select * from [table] where chanpin like '%" & keyword & "%' and dizhi='" & dizhi & "'"
end if
rs.open sql,conn,1,1
%>
...... '余下楼上自己补充