一段ASP多條件查詢的代碼
讀者表(ID,NAME,SEX,DEPT,GRADE)。IIS運行提示FROM子句錯誤。
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
%>
sql="select * from reader"
->
sql="select * from reader where "