逗号链接的字符串模糊查询怎样写?
2013-04-19 12:05
302 查看
表名 table1
字段
id uid
1 1,2
2 2,6,11
3 2
4 3,4
5 4,5,7
6 6,9
如id=2,查询得到
id uid
1 1,2
2 2,6,11
3 2
SQL code
http://bbs.csdn.net/topics/300156383
字段
id uid
1 1,2
2 2,6,11
3 2
4 3,4
5 4,5,7
6 6,9
如id=2,查询得到
id uid
1 1,2
2 2,6,11
3 2
CHARINDEX(',',NAME)-1指定某字段中逗号开始的位置,-1是去除‘,’本身的位置
SQL code
create table table1 (id int, uid varchar(10)) insert into table1 values(1 , '1,2') insert into table1 values(2 , '2,6,11') insert into table1 values(3 , '2') insert into table1 values(4 , '3,4') insert into table1 values(5 , '4,5,7') insert into table1 values(6 , '6,9') go declare @uid as int set @uid = 2 select * from table1 where charindex(','+cast(@uid as varchar) + ',' , ','+ uid +',') > 0 /* id uid ----------- ---------- 1 1,2 2 2,6,11 3 2 (所影响的行数为 3 行) */ select * from table1 where ','+ uid +',' like '%,'+cast(@uid as varchar) + ',%' /* id uid ----------- ---------- 1 1,2 2 2,6,11 3 2 (所影响的行数为 3 行) */ drop table table1
http://bbs.csdn.net/topics/300156383
相关文章推荐
- MYSQL查询某字段中以逗号分隔的字符串的方法
- 把字符串赋给变量,然后执行,模糊查询的问题
- 使用Damerau-Levenshtein自动机实现字符串模糊查询
- mysql使用参数化查询,like模糊查询,应如何拼接字符串
- mysql:查询以逗号相隔的字符串
- 怎样查询反向链接?
- MYSQL中利用select查询某字段中包含以逗号分隔的字符串的记录方法
- MYSQL中利用select查询某字段中包含以逗号分隔的字符串的记录方法
- MySql 查询以逗号分隔的字符串的方法(正则)
- sql语句查询某字段中包含指定字符串的数据列表,完全匹配字段中逗号中间的字符串数据
- 怎样查询反向链接?[转]
- Google字符串模糊匹配算法,字典树模糊查询
- 解决mysql查询,in条件参数为带逗号的字符串,查询结果错误
- oracle 将查询结果中的一列多个结果合并为一个字符串 并以逗号格开
- MySql 查询以逗号分隔的字符串的方法(正则)
- MYSQL中模糊查询带逗号间隔的字符(FIND_IN_SET)
- mysql 在2个table中查询用逗号的id字符串
- MYSQL查询某字段中以逗号分隔的字符串的方法
- 再谈怎样以最简单的方法将泛型为String类型的集合或String类型的数组转化为逗号间隔字符串形式
- sql 数据库,左外链接和查询结果某一项添加自定义字符串的情况