读书人

SQL 字符串有关问题

发布时间: 2012-10-20 14:12:47 作者: rapoo

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 t1select '1,2,3,4,5' union allselect '2,3,4,5,6' union allselect '5,7,8,9,0' union allselect '11,34,234,52' union allselect '3,6,8,9'select * from t1select * from t1 where LEN(a1)-len(REPLACE(a1,'3',''))>0
[解决办法]
SQL code
select * from t1 where LEN(a1)-len(REPLACE(a1,'3',''))>0 

读书人网 >SQL Server

热点推荐