我想这样,有几个变量a,b,c,如果A为1时,查性别为男,如果B为1查年龄大于22的人,如果C为1,查姓名姓王的人。
怎么做呢?!!A,B,C是复选,可能同时为1 ,可能同时都不为1。
如果A,B,C同时为1要同时查性别为男年龄大于22姓王的人
如果都不为1则显示所有的了。怎么做啊。帮帮我。

解决方案 »

  1.   

    StrTemp:='';
    if a=1 then
      StrTemp:=' where 性别=''男'' ';
    if b=1 then
    begin
      if StrTemp='' then
        StrTemp:=' where 年龄>22 '
      else
        StrTemp:=StrTemp+' and 年龄>22 ';
    end;
    if c=1 then
    begin
      if StrTemp='' then
        StrTemp:=' where substring(姓名,1,1)=''王'' '
      else
        StrTemp:=StrTemp+' and substring(姓名,1,1)=''王'' ';
    end;
    StrSql:='select * from table '+StrTemp;
      

  2.   

    up,这不是什么sql语句问题,只是前台的变量判断而已。
    同意一楼
      

  3.   

    heixiu1980(迷茫ing)的方法非常好,谢谢!不过我说时没太说清,所以再麻烦大家一下。
    有三组选项,A组,B组,C组,其中A组有A1,A2,A3,B组有B1,B2,B3,C组有C1,C2,C3
    情况是A组是姓名,B组是年龄,C组是职位,A1是姓王,A2是姓李,A3是姓张,B1是1岁到10岁,B2是11岁到20岁,B3是21岁到30岁,C1是技术员,C2是工程师,C3是高工。我想设计查找,A1-A3,B1-B3,C1-C3全是可选项,A,B,C组之间是AND的关系,A1-A3之间是或的关系,比如,我可以查姓王或姓张的10岁到30之间的工程师。不过AND优先与OR,所以写程序有点乱,请大家请点一下。
      

  4.   

    StrTemp:='';
    if a=1 then
      StrTemp:=' where 性别=:psex';
    if b=1 then
    begin
      if StrTemp='' then
        StrTemp:=' where 年龄>:page '
      else
        StrTemp:=StrTemp+' and 年龄>:page ';
    end;
    if c=1 then
    begin
      if StrTemp='' then
        StrTemp:=' where 姓名 like :pname'
      else
        StrTemp:=StrTemp+' and 姓名 like :pname';
    end;
    StrSql:='select * from table '+StrTemp;然后设置各个参数的值就ok了