473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SQL Statement Replce text in a column

I am trying to write an sql statement that replaces a string in a column
from one value to another

The table contains email addresses and some start with 'w*******@domain.com'

I want to be able to remove the www. part of the string

any help would be grateful
craig

Jul 20 '05 #1
4 3008
Craig Keightley wrote:
I am trying to write an sql statement that replaces a string in a column
from one value to another

The table contains email addresses and some start with 'w*******@domain.com'

I want to be able to remove the www. part of the string


# Do you know the exact string which you want to replace? If yes:
update tablename set email='new address' where email='old address';

# Or do you just know that you want to remove www. on the
# beginning of all rows where it exists?
update tablename
set email=SUBSTRING( email, 5 )
where email like 'www.%';
Jul 20 '05 #2
"Aggro" <sp**********@yahoo.com> wrote in message news:qJFxc.265
# Or do you just know that you want to remove www. on the
# beginning of all rows where it exists?
update tablename
set email=SUBSTRING( email, 5 )
where email like 'www.%';


There is also REPLACE, which is useful for replacing substrings anywhere in
the string.

set email = REPLACE(email, 'www.', '');

But it will replace www. anywhere in the string, which is not the same thing
as your original code.

Does anyone know if the search string, or the 2nd argument, can be a regular
expression?
Jul 20 '05 #3
Siemel Naran wrote:
There is also REPLACE, which is useful for replacing substrings anywhere in
the string.

set email = REPLACE(email, 'www.', '');

But it will replace www. anywhere in the string, which is not the same thing
as your original code.


I know this, and I thought that searching for like 'www.%' would be
faster, rather than using a search anywhere in the middle of the string,
because when searching only from the left side, we can use indexes if
they exist.

And also, like you said, replace will also change values in the middle
of the string, and that is not what we want. So I see no reason, why we
should think about how to get replace to work correctly.
Jul 20 '05 #4
Siemel Naran wrote:
Does anyone know if the search string, or the 2nd argument, can be a regular
expression?


Tried it, and I would say that it is not possible.

If I use something like replace( email, '^www.', '' ), it would find
only rows which start with the "^www." including the first character
(unlike it would work with regular expressions.)

I also tried:

replace( email, email REGEXP '^www.', '' )

But that doesn't either work, because email REGEXP '^www.' would just
return 0 or 1 depending wether the url starts with www. or not. So that
would replace 0 or 1 characters in the string.

I got no other ideas how it cold work.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
2
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error from the code below! Error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint...
4
by: bbdobuddy | last post by:
Hi, I have an ASP.net application with a connection to a sql database. I am writing a SQL statement to update some fields in a table but it won't run because it gives me an error that says ...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
3
by: Munno | last post by:
Hi All, I am not so proficient in SQL and seek your help. I have a column by the name of Mask in a table, which has text eg. (YYYYYYYNNNNYYYYYYYYYNNYYYY). I wanted to update one particular...
3
by: Deano | last post by:
Hi, I just want to add a text column to a table in my code. I can't find a simple example of this. dbs.Execute ("ALTER tblCCOccurrences ADD COLUMN Year1 Text;"). This gives me; Syntax...
4
by: AKdlm | last post by:
I am using Access 97 (I know) and am creating a lost and found database for materials in our company. I have it all set up so an employee can enter a sales order and pick a specific line/multiple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.