一个关于条件判断的问题
在做一个select查询,条件由用户输入,如果用户选择any,该怎么处理呢
例如:select * from tablename where field1=@field1 and field2=@field2,...
如果用户@field1选了 "any ",field1=@field1这里怎么处理呢?
[解决办法]
select * from tablename
where field1=isnull(@field1, field1) and field2=isnull(@field2, field2)
...
[解决办法]
select * from tablename where (field1=@field1 or @field1 is null) and (field2=@field2 or @field is null)
对空值处理一下就好了
[解决办法]
select * from tablename where (field1=@field1 or @field1 is null) and (field2=@field2 or @field2 is null)
对空值处理一下就好了
[解决办法]
select * from tablename
where field1=isnull(@field1, field1) and field2=isnull(@field2, field2)