日期:2014-05-18  浏览次数:20453 次

号码问题
我这里有一个手机号码表,需要对号码的最后四位进行处理,凡是满足
后四位为这种类型的都删除:
AAAA
ABAB
AABB
BBAA
BABA
AAAB
BBBA
ABBB
BAAA
我有个笨办法,但是想寻求个高效的,谢谢

------解决方案--------------------
--写了个函数,当符合时为1,不符合为0
create function testnum (@s varchar(4)) returns bit as
begin
declare @A varchar(1),@B varchar(1),@ret bit
set @A=substring(@s,1,1)
set @B=case when substring(@s,2,1) <> @A then substring(@s,2,1)
when substring(@s,3,1) <> @A then substring(@s,3,1)
when substring(@s,4,1) <> @A then substring(@s,4,1) end
set @s=replace(@s,@A, 'A ')
set @s=replace(@s,@B, 'B ')

if @s in ( 'AAAA ', 'ABAB ', 'AABB ', 'AAAB ', 'ABBB ') set @ret=1 else set @ret=0
return @ret
end
--try
delete from table where dbo.testnum(haoma)=1