用空字符串替换除数字以外的字符

来源:互联网 发布:制作木马软件 编辑:程序博客网 时间:2024/05/14 22:58

alter table table1 add id int identity(1,1)
go
declare @val varchar(10),@i int,@len int,@tel varchar(2000),@id int
select @val=''
declare ytbelwxg cursor for select id,c from table1
open ytbelwxg
fetch next from ytbelwxg into @id,@tel
while @@fetch_status=0
  begin
    select @i=1
    select @len=len(@tel)
    while @i< =@len
      begin
        select @val=substring(@tel,@i,1)
        if isnumeric(@val)=0
          update table1 set c= replace(c,@val,'')
        select @i=@i+1
      end
    fetch next from ytbelwxg into @id,@tel
  end
close ytbelwxg
deallocate ytbelwxg
go
alter table  table1  drop column id
go
select * from table1

原创粉丝点击