select * from 表 where charindex(',22,', ',' + b + ',') > 0 and charindex(',4,' ',' + b + ',') > 0
select * from tb where charindex(',22,' , ',' + b + ',') > 0 and charindex(',4,' , ',' + b + ',') > 0
select * from 表 where charindex(',22,',','+b+',')>0 and charindex(',4,',','+b+',')>0
--这两种都行. select * from tb where charindex(',22,' , ',' + b + ',') > 0 and charindex(',4,' , ',' + b + ',') > 0select * from tb where ',' + b + ',' like '%,22,%' and ',' + b + ',' like '%,4,%'
谢谢大家,问题解决了,发现LS给出的答案当字段中只为"22,4"时,该记录无法被查询出,故做了如下修改 select * from table1 where charindex('22' , ',' + aaa + ',') > 0 and charindex('4' , ',' + aaa + ',') > 0 声明,此帖并非想考大家,而是真的忘记用charindex这个函数了,并且调试中发现了如上问题,进行了改正
where charindex(',22,', ',' + b + ',') > 0 and charindex(',4,' ',' + b + ',') > 0
select * from tb where charindex(',22,' , ',' + b + ',') > 0 and charindex(',4,' , ',' + b + ',') > 0select * from tb where ',' + b + ',' like '%,22,%' and ',' + b + ',' like '%,4,%'
select * from table1 where charindex('22' , ',' + aaa + ',') > 0 and charindex('4' , ',' + aaa + ',') > 0
声明,此帖并非想考大家,而是真的忘记用charindex这个函数了,并且调试中发现了如上问题,进行了改正