select * from t
where (@A='' AND @B='')
  or (@A is not null and @B is null and Field like '%'+@A+'%')
  or (@A is null and @B is not null and Field like '%'+@B+'%')
  or (@A is not null and @B is not null and Field>=@A and Field<=@B)

解决方案 »

  1.   


    最好不要用拼接字符串的形式
    ============================
    我只能告诉你,用拼接字串是最好的形式。比如,全为空的情况下,不用搜索条件,是最快的查询,如果你还要弄一个条件,显然不太好。
      

  2.   

    这种情况不拼字符串,我倒还没见识过。那位高手可以帮忙啊
      

  3.   


    最好不要用拼接字符串的形式
    ============================
    我只能告诉你,用拼接字串是最好的形式。比如,全为空的情况下,不用搜索条件,是最快的查询,如果你还要弄一个条件,显然不太好。