日期:2014-05-17 浏览次数:20686 次
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([col1] int,[col2] varchar(14))
insert [tb]
select 11,'11,12,13,14,15' union all
select 21,'21,22,23,24,25' union all
select 31,'21,22,23'
--------------开始查询--------------------------
select a.col1 from tb a,tb b where a.col1=b.col1 and CHARINDEX(','+ltrim(a.col1)+',',','+b.col2+',')>0
----------------结果----------------------------
/* col1
-----------
11
21
(2 行受影响)
*/