22,209
社区成员
发帖
与我相关
我的任务
分享
---------------------------------------------
--> Author : jinjazzli
--> Target : ---->1000
--> Date : 2009-12-15 10:33:45
--> Version: SQL Server 2005
---------------------------------------------
--> 测试数据: @tb
declare @tb table (id varchar(100))
insert into @tb
select '7,67,47' union all
select '1,2,3,4,5,6,7' union all
select '22,33,44,55,66' union all
select '12,13,14,15'
declare @s1 varchar(10),@str varchar(1000)
set @s1='7,66,47'
set @str='select '+isnull(@str,'')+replace(@s1,',',' as id union all select ')
create table #t(id varchar(10))
insert #t exec(@str)
select distinct b.* from @tb b,#t a
where charindex(','+a.id+',',','+b.id+',')>0
id
----------------------------------------------------------------------------------------------------
1,2,3,4,5,6,7
22,33,44,55,66
7,67,47
drop table #t