日期:2014-05-18 浏览次数:20488 次
declare @s varchar(100) set @s = '11,12,113,141,151' -- 去除单引号 ;with t as( select vt=(case when charindex(',',@s)>0 then substring(@s, charindex(',',@s)+1, len(@s)) else '' end), st=(case when charindex(',',@s)>0 then left(@s, charindex(',',@s)-1) else @s end) union all select vt=(case when charindex(',',t.vt)>0 then substring(t.vt, charindex(',',t.vt)+1, len(t.vt)) else '' end), st=(case when charindex(',',t.vt)>0 then left(t.vt, charindex(',',t.vt)-1) else t.vt end) from t where len(t.vt)>0 ) insert into 表A(字段B) select st from t where t.st not in(select 字段B from 表A)