我的列ServicetTypeIDs包含以下数据。我使用下面的where子句来搜索值,假设如果我的参数@ServiceTypes = 1,9,它只会在两个参数都存在的情况下返回记录。我想返回包含1、9或本身包含1、9的记录的记录。我的where子句不正确。请帮帮忙
column
1
NULL
9
1
4,7
1,9
WHERE
( @ServiceTypes is null or
charindex(','+SEP.ServiceTypeIDs+',',
','+@ServiceTypes+',') > 0)))发布于 2012-07-30 15:59:13
如果您需要for '1,9‘select ('1','9','1,9'),这里有一个简短的条件
where (@ServiceTypes is null) or (','+@ServiceTypes+',' like '%,'+ServiceTypeIds+',%')但是对于'4,9‘,它只选择('9')。如果你想得到这个掩码的('4,7','1,9','9'),下面是条件
where (@ServiceTypes is null)
or
(','+ServiceTypeIds+',' like ',%'+SUBSTRING(@ServiceTypes,1,charindex(',',@ServiceTypes)-1)+',%')
or
(','+ServiceTypeIds+',' like ',%'+SUBSTRING(@ServiceTypes,charindex(',',@ServiceTypes)+1,1000)+',%') https://stackoverflow.com/questions/11713565
复制相似问题