一段ASP多条件查询的代码
读者表(ID,NAME,SEX,DEPT,GRADE)。IIS运行提示FROM子句错误。
<%
action1=request.QueryString("action1")
action2=request.QueryString("action2")
action3=request.QueryString("action3")
action4=request.QueryString("action4")
action5=request.QueryString("action5")
set rs=server.createobject("adodb.recordset")
sql="select * from reader"
if action1<>"" then
sql=sql&" reader_id like '%"&action1&"%' "
flag=1
end if
if action2<>"" and flag=1 then
sql=sql&" and reader_name like '%"&action2&"%'"
flag=1
elseif action2<>"" then
sql=sql&" reader_name like '%"&action2&"%'"
flag=1
end if
if action3<>"" and flag=1 then
sql=sql&" and reader_sex like '%"&action3&"%'"
flag=1
elseif action3<>"" then
sql=sql&" reader_sex like '%"&action3&"%'"
flag=1
end if
if action4<>"" and flag=1 then
sql=sql&" and reader_dept like '%"&action4&"%'"
flag=1
elseif action4<>"" then
sql=sql&" reader_dept like '%"&action4&"%'"
flag=1
end if
if action5<>"" and flag=1 then
sql=sql&" and reader_grade like '%"&action5&"%'"
flag=1
elseif action5<>"" then
sql=sql&" reader_grade like '%"&action5&"%'"
flag=1
end if
if flag=0 then
sql="select * from reader order by reader_id asc"
end if
rs.open sql,conn,1,1
rs.close
%>