TABLE
F1 F2
A1,BB,C ABC,CC
AA BC,QQQ
A1A ABCD,ZZ
现在F1=A1,F2=ABC
求WHERE条件的写法,定位到一条记录。
------解决方案--------------------
- SQL code
select * from [TABLE]where charindex(',A1,',','+F1+',')>0and charindex(',ABC,',','+F2+',')>0
------解决方案--------------------
- SQL code
select * from TB where charindex('A1,',F1+',')>0 And Charindex('ABC,',F2+',')>0
------解决方案--------------------
- SQL code
if object_id(N'[t]') is not null drop table [t]gocreate table t([F1] varchar(10),[F2] varchar(10))goinsert into tselect 'A1,BB,C','ABC,CC' union allselect 'AA','BC,QQQ' union allselect 'A1A','ABCD,ZZ'godeclare @f1 varchar(10),@f2 varchar(10)select @f1='A1',@f2='ABC'select * from twhere charindex(',[email protected]+',',','+[F1]+',')>0 and charindex(',[email protected]+',',','+[F2]+',')>0/*(3 row(s) affected)F1 F2---------- ----------A1,BB,C ABC,CC(1 row(s) affected)*/
------解决方案--------------------