求一SQL,字段多值的问题
TABLE
F1 F2
A1,BB,C ABC,CC
AA BC,QQQ
A1A ABCD,ZZ
现在F1=A1,F2=ABC
求WHERE条件的写法,定位到一条记录。
[解决办法]
select * from [TABLE]where charindex(',A1,',','+F1+',')>0and charindex(',ABC,',','+F2+',')>0
[解决办法]
select * from TB where charindex('A1,',F1+',')>0 And Charindex('ABC,',F2+',')>0
[解决办法]
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(','+@f1+',',','+[F1]+',')>0 and charindex(','+@f2+',',','+[F2]+',')>0/*(3 row(s) affected)F1 F2---------- ----------A1,BB,C ABC,CC(1 row(s) affected)*/
[解决办法]