如何实现SQL的多条件模糊查询

我现在的查询语句是:
sql="select * from TABLE where 问题1 like '"+答案1+"' and 问题2 like '"+答案2+"' and 问题3 like '"+答案3+"'……"
但是现在问题来了,有很多,那么
sql="select * from TABLE where 问题 like '"+答案+"' order by id"
请问这一句里的“问题”和“答案”都是上一个页面传递过来的多个值,请问该如何实现多条件模糊查询呢?

你传过来的格式是固定的,如果你用拼SQL的方式来查询的话那么用
字符串的replace一次性将格式转化成like ‘ 的格式就行了。
如果用存储过程的话,做一个参数是XML类型的存储过程,直接将这些条件以XML的格式传进去就行了,也很方便
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-17
ere (1=1)"

if (exp1) then
str=str&" and ( 条件1)"
end if
if (exp2) then
str=str&" and ( 条件2)"
end if
if (exp3) then
str=str&" and ( 条件3)"
end if

str=str&" order by id desc"
第2个回答  2011-03-16
if(答案=“”)答案=null;
sql="select * from TABLE where 问题1 like '%"+答案1+"%' and 问题2 like '%"+答案2+"%' 问题3 like '%"+答案3+"%' order by id”;
第3个回答  2011-03-17
你用的什么数据库

为什么用like 而不是等号呢

为什么用那么多参数呢 少点问题不行吗