日期:2014-05-19  浏览次数:20541 次

如何找含字符串的子串的记录?
如找含“sm01”的记录
“sm02,sm00,”没有, "sm02,sm01, "就有,如何写语句找到?是用Instr吗?

------解决方案--------------------
select *From 表 where 字段 like '%sm01% '
------解决方案--------------------
这样也行

select * From 表 where charindex( 'sm01 ',字段)> 0
------解决方案--------------------
“sm02,sm00,”没有, "sm02,sm01, "就有

“sm02,sm00,sm010” 呢?如果不算有的话,用charindex()函数如下:

select *
From 表名
where charindex( ',sm01, ', ', ' + 字段名 + ', ')> 0