日期:2014-05-18 浏览次数:20551 次
--a1 a2 a3 a4 a5 a6 declare @var varchar(40) set @var='1,2,7 33,32,34' with tb as ( --虚拟出一张表 select 1 as a1,2 as a2,3 as a3,4 as a4,5 as a5,6 as a6 union all select 1,7,8,9,2,11 union all select 2,11,21,22,23,34 union all select 1,56,54,57,50,51 ) select * from tb where case when CHARINDEX(LTRIM(a1),@var)>0 then 1 else 0 end + case when CHARINDEX(LTRIM(a2),@var)>0 then 1 else 0 end + case when CHARINDEX(LTRIM(a3),@var)>0 then 1 else 0 end + case when CHARINDEX(LTRIM(a4),@var)>0 then 1 else 0 end + case when CHARINDEX(LTRIM(a5),@var)>0 then 1 else 0 end + case when CHARINDEX(LTRIM(a6),@var)>0 then 1 else 0 end >1 --删除方法 --delete from tb_name where (把where 下面的case 语句+case语句 >1 粘贴下) /* a1 a2 a3 a4 a5 a6 ----------- ----------- ----------- ----------- ----------- ----------- 1 2 3 4 5 6 1 7 8 9 2 11 2 11 21 22 23 34 (3 row(s) affected) */
------解决方案--------------------
顶二楼了。。
------解决方案--------------------
只是没用过类似的方法 ,效率应该会很低吧。