Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 replace(field,'=[0-9]','')

Author  Topic 

davidagnew37
Starting Member

33 Posts

Posted - 2007-11-16 : 16:07:55
hi,

is it possible to do a replace a specify a range like 0-9.

I need to replace an "=" + any number [0-9]

i.e.

declare @var varchar(20)
set @var = '0=Edwige_4t07,1=Testeurs_reduits,Count=2'
select replace(@var,'=[0-9]','')

and i want @var to equal 'Edwige_4t07,Testeurs_reduits,Count'

is that possible?

thanks
David


jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-11-16 : 16:40:05
Here are two options, there are other ways to go as well as I am sure some will suggest ...

1) use nested replaces like this:

replace(replace(replace(@var,'0',''), '1',''), '2', '') ... etc ...

2) You can use a Regular Expression replace, if you have access to Visual Studio and permissions to use CLR code, and understand how to use all that stuff, as shown here:http://weblogs.sqlteam.com/jeffs/archive/2007/04/27/SQL-2005-Regular-Expression-Replace.aspx

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -