你这语句写的自己都哭了吧,一般sql拼接是这么做的,我给你写个伪代码
设初始sql= "select * from 档案 where 1=1"
设combo1,2,3,4分别为4个查询条件
if Combo1.Text<>全部
then sql=sql&"and 姓名=‘"&姓名变量&“’”
......
if Combo4.Text<>全部
then sql=sql&"and 体重=‘"&体重变量&“’”,1=1在百万数量级以上会有效率问题,但小型应用可不考虑。
SQL = "select * from 档案 where 1 = 1 "
If Combo1.Text <> "全部" Then
SQL = SQL & " and " & "姓名='" & Combo1.Text & "'"
End if
If Combo2.Text <> "全部" Then
SQL = SQL & " and " & "年龄='" & Combo2.Text & "'"
End if
If Combo3.Text <> "全部" Then
SQL = SQL & " and " & "身高='" & Combo3.Text & "'"
End if
If Combo4.Text <> "全部" Then
SQL = SQL & " and " & "体重='" & Combo4.Text & "'"
End if
Combo1.Text :=Combo1.Text='全部'?'':Combo1.Text;
Combo2.Text :=Combo2.Text='全部'?'':Combo2.Text;
Combo3.Text :=Combo3.Text='全部'?'':Combo3.Text;
Combo4.Text :=Combo4.Text='全部'?'':Combo4.Text;
select * from 档案 where 姓名 like '%Combo1.Text%' and 年龄 like '%Combo2.Text%' and 身高 like '%Combo3.Text%' and 体重 like '%Combo4.Text%';
select * from a where b in(‘1’ , ‘2’, ‘3’) and c <> '4'
这样可以么?