日期:2014-05-17 浏览次数:20767 次
select * from tb where emp_degree like'%a%'
or
select * from tb where charindex('a',emp_degree)>0
select * from tb where ',' + emp_degree + ',' like'%,a,%'
or
select * from tb where charindex(',a,',',' + emp_degree + ',')>0
select * from tb where charindex(','+'a'+',',','+emp_degree+',')>0
declare @t table(emp_no int,emp_name varchar(10),emp_degree varchar(10))
insert into @t select 1,'keven','a,b,c' union all
select 2,'nike','a,b' union all
select 3,'mical','b';
select a.emp_no,a.emp_name,b.v1 from (
select emp_no,emp_name,cast('<root><d>'+REPLACE(emp_degree ,',','</d><d>')+'</d></root>' as xml) as val from @t
) a
outer apply (
select v1=N.v.value('.','varchar(10)') from a.val.nodes('/root/d') N(v)
) b
/*
emp_no emp_name v1
----------- ---------- ----------
1 keven a
1 keven b
1 keven c
2 nike a
2 nike b
3 mical b
*/