简体   繁体   中英

Remove Alphabetic Characters in SQL Server

I need to change

ABC2001  
ABCD2001 
ASDF111111

to

2001
2001
111111

I need to remove alphabetic characters in SQL Server, any idea?

The function below will take care

create function NoLetters(@string2number varchar(200)) 
 returns varchar(200)
as
begin
  declare @c int
  declare @num varchar(200)
  set @num = ''
  declare @txtCurrent char(1)
  set @c=1
  while @c<=len(@string2number)
    begin
     set @txtCurrent = substring(@string2number,@c,1)
     if ascii(@txtCurrent) between 48 and 57
       set @num = @num + @txtCurrent
     set @c=@c+1
   end
 return @num
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM