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