共有六个查询条件,如下ls_company_no, ls_warehouse_no, ls_warehouse_loca_no, ls_cargo_name, ls_flag_warehouse_io, ld_date_lower<=date_warehouse_io<=ld_date_upper查询时用到的条件个数不定,以前做的使用多重case,现在想换种方式,请各位高手帮忙想想办法。谢谢!!

解决方案 »

  1.   

    关键是处理好and,我的办法是先判断下一个条件是否为空,不为空就加and。
      

  2.   

    esu(ESU)的意思是使用一个肯定为真的条件“1>0”  然后就直接and……就可以了
      

  3.   

    同意 esu(ESU), fengjn(小枫) 棏
    str:='select * from table where 1>0 ';if edit1.text<>'' then
      str:= str+' and name='+quotedstr(edit1.text);
    if edit2.text<>'' then
      str:= str+' and sex='+quotedstr(edit2.text);......
      

  4.   

    楼上的各位高手,按照这种方法,会有多少种情况,很多吗,21种?请指教,谢谢。-------------------------------
    同意 esu(ESU), fengjn(小枫) 棏
    str:='select * from table where 1>0 ';if edit1.text<>'' then
      str:= str+' and name='+quotedstr(edit1.text);
    if edit2.text<>'' then
      str:= str+' and sex='+quotedstr(edit2.text);
      

  5.   

    写一个永远为真的条件,再加 and  条件
      

  6.   

    同意楼上
    s = "......where 1 = 1 ";
    while()
    {
      s = s + "and " + ....;
    }
      

  7.   

    多谢各位!
    这页分有点少,在下边的帖子补上http://expert.csdn.net/Expert/topic/2059/2059330.xml?temp=.8275415up有分;