create table #t2 ( [name] varchar(20), hobby varchar(100) )insert #t2select 'John','football,fishing,volleyball' union select 'Tom','pingpong,basketball' union select 'Jane','running,pingpong'--最关键代码 select [name] from #t2 where CHARINDEX('pingpong',hobby)>0 这样写也行。
declare @t table(name varchar(10),hobby varchar(100))insert into @t select' John','football,fishing,volleyball' union all select' Tom','pingpong,basketball' union all select' Jane','running,pingpong' select * from @t where hobby like'%pingpong%' name hobby Tom pingpong,basketball Jane running,pingpong (影響 2 個資料列)
select name from table where hobby like '%pingpong%'
select * from table where hobby like '%pingpong%'
select * from TableName where len(hobby)<>len(hobby)-len(replace(hobby,'pingpong',''))
(
[name] varchar(20),
hobby varchar(100)
)insert #t2select 'John','football,fishing,volleyball'
union
select 'Tom','pingpong,basketball'
union
select 'Jane','running,pingpong'--最关键代码
select [name] from #t2 where CHARINDEX('pingpong',hobby)>0
这样写也行。
declare @t table(name varchar(10),hobby varchar(100))insert into @t
select' John','football,fishing,volleyball' union all
select' Tom','pingpong,basketball' union all
select' Jane','running,pingpong'
select * from @t where hobby like'%pingpong%'
name hobby
Tom pingpong,basketball
Jane running,pingpong
(影響 2 個資料列)
where len(hobby)<>len(hobby)-len(replace(hobby,'pingpong',''))