我在构建where子句的时候 对其中一个字段允许有多个值 该怎么写这个句子呢?
具体情况是 a 的可用值是1,2,3,4 用户可以选择多个值
比如用户选了 1,3,4
我现在的where子句要检索出a=1或者a=3或者a=4且a!=2的所有结果
注意where子句除了条件a 还有其他条件b,c,d....
这个句子应该怎么写好?
具体情况是 a 的可用值是1,2,3,4 用户可以选择多个值
比如用户选了 1,3,4
我现在的where子句要检索出a=1或者a=3或者a=4且a!=2的所有结果
注意where子句除了条件a 还有其他条件b,c,d....
这个句子应该怎么写好?
declare @str varchar(20)
set @str='1,2,3,4'
select * from tbl where charindex(','+ltrim(a),','+@str)>0
where charindex(','+cast(a as varchar)+',' , ','+@s+',') > 0 and 其他条件
或
where ','+@s+',' LIKE '%,'+cast(a as varchar)+',%' and 其他条件
and a not in( select a=4 union select 5 union select 6)
and b....
and c....