日期:2014-05-18 浏览次数:20499 次
create table tb(s varchar(20)) insert into tb select '101,102,103,107' insert into tb select '102,103,107' insert into tb select '103,101,1077' declare @sql varchar(8000) set @sql='103,101,107' set @sql='select * into ## from (select '+replace(@sql,',',' as id union all select ')+')tp' exec(@sql) declare @where varchar(8000) select @where=isnull(@where+' and ','')+'charindex('','+ltrim(id)+','','',''+s+'','')>0' from ## exec('select * from tb where '+@where)