?
Solved

remove numbers in a sql string

Posted on 2004-10-19
4
Medium Priority
?
425 Views
Last Modified: 2009-07-29
I have a field from where I want to remove the numbers.
Examples
12 Me me
125 just think
56 again
I doesn't have a pattern. Should I use PATINDEX or CHARINDEX?
0
Comment
Question by:Ilianam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
mcmonap earned 1500 total points
ID: 12348580
Hi Ilianam,

A simple loop might do what you want, this will remove numbers 0 to 9:

--start code
DECLARE @i INT
SET @i = 0
WHILE @i < 10
BEGIN
      UPDATE <your table name> SET <you column name> = REPLACE(col1,@i,'')
      SET @i = @i+1
END
--end code
0
 

Author Comment

by:Ilianam
ID: 12348628
I think in that case I will need a cursor in order to navigate through the whole table. Is that true?
0
 
LVL 6

Expert Comment

by:RaisinJ
ID: 12348726
No, your will not need a cursor, mcmonap's code above will update the netire column.  It'll just simply replace any intergers, 0-9 with ''.  If they do not exist in a certain record, nothing will take place.
0
 
LVL 6

Expert Comment

by:RaisinJ
ID: 12348759
If you need to update mutiple columns, you can include that in the one update statement.  e.i.:

UPDATE <your table name> SET <col1> = REPLACE(col1,@i,''), <col2> = REPLACE(col2,@i,''), <col3> = REPLACE(col3,@i,'')
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question