If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > How to change the content?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-12-06, 14:02
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
How to change the content?

Hi there !

I'm quite desperate as I can't find a quick method to partially change the content of a field.

I explain:
In a field named 'notes', PART of the content is:
Code:
<a href='mailto:"abc@domain.com"'>abc@domain.com</a>
This content is wrong.

It must be:
Code:
<a href="mailto:abc@domain.com">abc@domain.com</a>
How can I make the change with a SQL Query instead of manually make the change row by row (approximately 1500 rows contain the error!!!) considering the fact that abc@domain.com is different in each of the rows?

Many thanks in advance for any help!

Best regards,

Gerard
Reply With Quote
  #2 (permalink)  
Old 11-12-06, 14:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
update daTable
   set notes=replace(replace('href=''mailto:"','"mailto:'),'''>','">')
 where notes like '%href=''mailto:"%">%'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-12-06, 14:53
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
Quote:
Originally Posted by r937
Code:
update daTable
   set notes=replace(replace('href=''mailto:"','"mailto:'),'''>','">')
 where notes like '%href=''mailto:"%">%'
Hi !

Thank you for replying. I appreciate.
But, as I'm quite old and learning, I want to really understand the syntax I'll write.

Some questions arise:
1 - Why have we "replace" repeated twice?
2 - The single and double quotes you wrote in your example doesn't correspond to those I put in my example.
3 - What will happen to the email addresses which are differents?

Be sure, professor, I certainly do not want to bother you! :-)

Best regards,

Gerard
Reply With Quote
  #4 (permalink)  
Old 11-12-06, 16:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
did you try it? what results did it give?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-12-06, 17:08
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
Yes, I tried... on a copy of the table!
After two attempts, this worked fine:
Code:
UPDATE `table_name` SET column_name = REPLACE(column_name, '"', '') WHERE column_name LIKE '%href=\'mailto:"%';
I thank you for your valuable help.

Best.
Reply With Quote
  #6 (permalink)  
Old 11-12-06, 17:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
all you have done is remove the double quotes

in other words, you've changed this --
Code:
<a href='mailto:"abc@domain.com"'>abc@domain.com</a>
to this --
Code:
<a href='mailto:abc@domain.com'>abc@domain.com</a>
which is not what you asked

you asked for this --
Code:
<a href="mailto:abc@domain.com">abc@domain.com</a>
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 11-12-06, 17:26
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
YES you are right about the kind of quotes but the principle remained the same: remove the extra quotes just before and after the address, no matter if the quotes are single or double. I opted for the single quotes which are more "orthodox"! :-)
Reply With Quote
  #8 (permalink)  
Old 11-12-06, 19:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
either single or double can be used

see http://www.w3.org/TR/html4/intro/sgm...tml#attributes

if you look at all the web sites out there (okay, just look at some, you don't really have to look at all of them) you will find that most of them use double quotes

also, the incidence of a single quote required inside a double-quoted string is more frequent than a double quote inside a single-quoted string

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 11-13-06, 07:58
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
You are right.
I have read about attributes in the page you mentioned.
And I tried to follow your advice and to replace the single quotes with double quotes.

For example, I tried to replace where it is necessary
Code:
<a href='mailto:abc@domain.com'>
with
Code:
<a href="mailto:abc@domain.com">
(Of course, this text isn't the only text contained in the field...)

I wrote:
Code:
UPDATE `table_name` SET column_name = REPLACE(column_name, '', "") WHERE column_name LIKE '%mailto:\'%';
This query has no effect!

What's wrong?

Last edited by Germaris; 11-13-06 at 08:05.
Reply With Quote
  #10 (permalink)  
Old 11-13-06, 08:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
REPLACE(column_name, '''', '"')
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 11-13-06, 08:30
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
Still no effect !
And I perfectly know that more than a thousand rows must be affected...

I wrote:
Code:
UPDATE `table_name` SET column_name = REPLACE(column_name, '''', '"') WHERE column_name LIKE '%mailto:\'%';
Reply With Quote
  #12 (permalink)  
Old 11-13-06, 08:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
you keep messing up in different places
Code:
WHERE column_name LIKE '%mailto:''%'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #13 (permalink)  
Old 11-13-06, 09:09
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
Maybe it's because I'm French but I don't understand what you mean: "you keep messing up in different places".

I wrote:
Code:
UPDATE `table_name` SET column_name = REPLACE(column_name, '''', '"') WHERE column_name LIKE '%mailto:''%';
...and nothing happens, right or wrong!
Reply With Quote
  #14 (permalink)  
Old 11-13-06, 09:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
what do you get for this query:
Code:
select count(*) from table_name where column_name LIKE '%mailto:''%'
and what do you get for this query:
Code:
select count(*) from table_name where column_name LIKE '%mailto:"%'
this should tell you why

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #15 (permalink)  
Old 11-13-06, 09:31
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
Both queries return zero !!!!!

Which isn't true !
Here is the copy of the REAL full content of the field in one the rows:
Code:
Autres adresses de courriel : <a href='mailto:jr.reverte@laposte.fr'><font color='#FF3300'>jr.reverte@laposte.fr</font></a> et <a href='mailto:entsoa23@fr.st'><font color='#FF3300'>entsoa23@fr.st</font> (cliquables).</a>
and I want to change it to:
Code:
Autres adresses de courriel : <a href="mailto:jr.reverte@laposte.fr"><font color='#FF3300'>jr.reverte@laposte.fr</font></a> et <a href="mailto:entsoa23@fr.st"><font color='#FF3300'>entsoa23@fr.st</font> (cliquables).</a>
This is driving me quite mad... :-) GRRRR !!!

Last edited by Germaris; 11-13-06 at 09:36.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On