22,209
社区成员
发帖
与我相关
我的任务
分享
create table ic(
id int paimary key identity(1,1),
name varcahr(50)
)
create table iclist
(
id int primary key identity(1,1),
icname varchar(200),
icid varchar(50),
ictime date
)
insert into iclist values('专题纪委会20141230第十次会议','10,19,30',getdate());
insert into iclist values('院技委会2015年(03)号会议通知','6,9,11',getdate());
insert into iclist values('院2015(10)号会议通知','23,12,15',getdate());
--只是想查询ic表中id在 iclist表中icid字段中的数据
--类似于
select * from ic where id in(select icid from iclist)
select b.* from ic a inner join iclist b on a.id=b.icid
select * from ic t
where exists(select 1 from iclist
where CHARINDEX(','+RTRIM(t.id)+',',','+icid+',')>0)