Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

remove numbers in a sql string

Posted on 2004-10-19
4
Medium Priority
?
438 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

618 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