Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I remove all numbers from a string?

Status
Not open for further replies.

SteveMe

MIS
Aug 30, 2002
83
US
DECLARE @Str as varchar(200)

Set @Str = 'a123b432c'


so that @Str will equal 1bc.

I will not know how many numbers or if there are numbers in a string. The patterns will be different.
 
One way

DECLARE @Str as varchar(200)

Set @Str = 'a123b432c'
select replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(@Str,'1',''),'2',''),'3',''),'4',''),'5',''),'6',''),'7',''),'8',''),'9',''),'0','')



Denis The SQL Menace
SQL blog:
Personal Blog:
 
10 replace statements....

DECLARE @Str as varchar(200)

Set @Str = 'a123b432c'

Set @Str = Replace(@Str, '0', '')
Set @Str = Replace(@Str, '1', '')
Set @Str = Replace(@Str, '2', '')
Set @Str = Replace(@Str, '3', '')
Set @Str = Replace(@Str, '4', '')
Set @Str = Replace(@Str, '5', '')
Set @Str = Replace(@Str, '6', '')
Set @Str = Replace(@Str, '7', '')
Set @Str = Replace(@Str, '8', '')
Set @Str = Replace(@Str, '9', '')


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top