当前位置: 代码迷 >> Sql Server >> 查询id是不是包含在id字符串中
  详细解决方案

查询id是不是包含在id字符串中

热度:121   发布时间:2016-04-24 08:51:55.0
查询id是否包含在id字符串中

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 * from ic t
where exists(select 1 from iclist
where CHARINDEX(','+RTRIM(t.id)+',',','+icid+',')>0)

------解决思路----------------------
select b.* from ic a inner join iclist b on a.id=b.icid
  相关解决方案