现在有a表,字段如下:
id,    name,  company_sh
1      aaa        111
2      ddd        
3      www        555
4      qqq        
5      eee        666  with ADOQ_company do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from A where company_sh like :a and name like :b order by id ');
      Parameters.ParamByName('a').Value := trim(Edit_sh.Text)+'%';
      Parameters.ParamByName('b').Value := '%'+trim(Edit_name.Text)+'%';
      Open;
    end;
现在的问题是如果company_sh记录为空的话,上面的语句就无法查出来这条记录了,请问要怎么把这条记录也能包含进来呢?

解决方案 »

  1.   

    select * from A where isnull(company_sh,'''') like :a and isnull(name,'''') like :b order by id 如果字段中有空值,一般都要用isnull,相关的你查一下SQL中的isnull说明和用法。
      

  2.   

    SQL.Add('select * from A where name like :b and (company_sh like :a or company_sh is null) order by id');
      

  3.   

    按照楼主的意思,也应该可以的,EDIT中为空"" 这样就是 LIKE "%"应该是所有记录
      

  4.   

    if trim(Edit_sh.Text)=''
    then sqlstr:='select * from A'
    ELSE//LIKE 查询
      

  5.   

    swcsoft(对不起,我踩到你尾巴了!) 
    你的这句真好!!