日期:2014-05-17  浏览次数:20424 次

SQL 字符串问题
我有一个表 table1中的一个A1字段为
a1
1,2,3,4,5
2,3,4,5,6
5,7,8,9,0
11,34,234,52
3,6,8,9

然后我有一个字符3,那么我想查找A1字段包含3的字符的记录
要效率高一点的方法,不用CHARINDEX 和like 方法,

------解决方案--------------------
SQL code

create table t1
(
    a1 varchar(20)
)
insert into t1
select '1,2,3,4,5' union all
select '2,3,4,5,6' union all
select '5,7,8,9,0' union all
select '11,34,234,52' union all
select '3,6,8,9'
select * from t1

select * from t1 where LEN(a1)-len(REPLACE(a1,'3',''))>0

------解决方案--------------------
SQL code
select * from t1 where LEN(a1)-len(REPLACE(a1,'3',''))>0