那么你可以先判断一下,是不是空,如果为空,就不要加到sql字符串中去了,这样就没你所说的问题了

解决方案 »

  1.   

    你可以加一个条件,这个条件是表中索引等决不为空的字段,然后如下:
    sql=select * from tablename where ID<>"" 
    if trim(cha1)<>"" then
      sql=sql +"and " + cha1
    end if
    if trim(cha2)<>"" then
      sql=sql +"and " + cha2
    end if
    .....
    就OK了
      

  2.   

    str = "select * from talbe where 1=1 "
    if char <> "" then
    str = str & "and " & char
    end if