Solved

remove numbers in a sql string

Posted on 2004-10-19
4
416 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
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
mcmonap earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now