首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL 字符串有关问题

2012-10-20 
SQL字符串问题我有一个表 table1中的一个A1字段为a11,2,3,4,52,3,4,5,65,7,8,9,011,34,234,523,6,8,9然后

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 

热点排行