日期:2014-05-17 浏览次数:20559 次
create table 表1(id int,uid int,idlist varchar(30))
insert into 表1
select 1 , 10 ,'3,5,7,9,12,30'
create table 表2(id int, title varchar(20))
insert into 表2
select 1, 'a' union all
select 2, 'b' union all
select 3, 'c' union all
select 4, 'd'
go
if OBJECT_ID('tempdb..#temp') is not null
drop table #temp
select *,
SUBSTRING(t.idlist, number ,CHARINDEX(',',t.idlist+',',number)-number) as v
into #temp
from 表1 t,master..spt_values s
where s.number >=1
and s.type = 'P'
and SUBSTRING(','+t.idlist,s.number,1) = ','
and t.uid = 10
select * from [表2] a
where exists (select idlist from #temp b where a.id = b.v)
/*
id title
3 c
*/
create table t1(id int,uid int,idlist varchar(100))
insert into t1
select 1,10,'3,5,7,9,12,30'
create table t2(id int,title varchar(100))
insert