sql查询同一字段的多个值

来源:百度知道 编辑:UC知道 时间:2024/06/19 21:08:42
VBScript的

我要写条SQL语句,查询某个字段type1,type2,这些字段可能有A、B、C、D、E等多个值,而且值取自一个FORM, 一般查询一个条件可以这样写:
select * from 表 where type1=‘”&request.form(“type1”)&“’type2=‘”&request.form(“type2”)&“’

那么如果不指定查询条件,要查询所有符合条件1或者符合条件2的记录该怎么写(即在form里面不指定type1或者type2的条件)?

解决了再加100分

dim type1,type2,whereStr
type1=request.form("type1")
type2=request.form("type2")
whereStr=" where 1=1"
if type1<>"" then whereStr=whereStr&" and type1='"&type1&"'"
if type2<>"" then whereStr=whereStr&" and type2="'&type2&"'"
sql="select * from [表]"&whereStr
这个sql就是你所要的查询语句,注意不要去掉各个引号中的空格