create table #临时表(a varchar(100)) declare @aaa varchar(8000) set @aaa=''insert #临时表 select * from (select ''''''+replace(@str,'','',''''''as str union all select '''''')+'''''') a'' exec(@aaa)
select * from 你的表 where exists (select 1 from #临时表 where '',''+你的表.classid+'','' like ''%,''+a+'',%'') go
drop table 你的表,#临时表 ---------------------------------------------------------------
create table #t( id varchar(10)) declare @str varchar(300) set @str=''fds,bbbf,eee,ddd,fff,hhhfg,dddde'' declare @i int declare @len int set @i = 1 set @str=''fds,bbbf,eee,ddd,fff,hhhfg,dddde''+'','' while @i < len(@str) begin insert #t select substring(@str,@i,charindex('','',@str,@i)[email protected]) set @i = charindex('','',@str,@i)+1 end select * from 数据表 a,#t b where charindex(b.id, a.classid) > 0
create table t (classid varchar(100)) insert t values(''aada,bbbf,ccc'') insert t values(''ddd,aaaaaa,fdsa'') insert t values(''vvvvvv,aaabbbb'')
declare @str varchar(500)
set @str=''fds,bbbf,eee,ddd,fff,hhhfg,dddde''
select top 500 identity(int,1,1) as id into #t from sysobjects
select distinct a.* from t a, ( select substring('',''+string+'','',id+1,charindex('','','',''+string+'','',id+1)-id-1) as string from (select @str as string) b,#t c where substring('',''+string+'','',id,8000) like '',_%'') d where charindex('',''+string+'','','',''+classid+'','')>0