Gossamer Forum
Home : General : Databases and SQL :

Replace '&' with 'and' in titles

Quote Reply
Replace '&' with 'and' in titles
Hi, I just can't figure how to do this with an SQL statement.

I want to replace all the '&' with 'and' in my category titles. Example 'Sports & Recreation' becomes 'Sports and Recreation'. I need to do this because my hyperlinks to thier directorires do not recognize the &.

The part the beats me is how to find and replace only the '&' part of the title.

UPDATE lsql_Category SET Title=.................................. HELP!
Quote Reply
Re: [sooke] Replace '&' with 'and' in titles In reply to
I would personally do this using Perl. That is, I would loop through each row, read the row and do a $_ =~ /&/and/g; before re-inserting the information.

I'm sure this can be done using pure SQL - I think you might be able to do this using some of the regex features? I'm not sure.

- wil
Quote Reply
Re: [sooke] Replace '&' with 'and' in titles In reply to
You don't really want perl much too much effort....

UPDATE lsql_Category SET Title = REPLACE(Title, '&', 'and')

Last edited by:

Paul: Apr 24, 2002, 2:18 AM
Quote Reply
Re: [Paul] Replace '&' with 'and' in titles In reply to
Are you sure of the syntax of your previous message? The following page doesn't match up with what the code you supplied:

http://www.mysql.com/doc/R/E/REPLACE.html

- wil
Quote Reply
Re: [Wil] Replace '&' with 'and' in titles In reply to
Yes Im sure ;)
Quote Reply
Re: [Paul] Replace '&' with 'and' in titles In reply to
Hm. OK. They just don't specify UPDATE anywhere, but saying that you should start the command with REPLACE ...

- wil
Quote Reply
Re: [Wil] Replace '&' with 'and' in titles In reply to
Mmm no you shouldn't. The way I have it is fine.

Last edited by:

Paul: Apr 24, 2002, 4:34 AM
Quote Reply
Re: [Wil] Replace '&' with 'and' in titles In reply to
You may also wanna replace & with & wouldn't you? I always thought Links SQL changed it to that upon submission into the SQL database?

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy.] Replace '&' with 'and' in titles In reply to
Mmm & isn't being submitted into the database anyway..."and" is Wink

...either way the answer is still no :)
Quote Reply
Re: [Paul] Replace '&' with 'and' in titles In reply to
???

>>>I want to replace all the '&' with 'and' in my category titles. <<<

Is it me, or does he specifically say he wants to replace ALL &'s with the word 'and', not the other way, as you are saying Paul ;)

I know it is wrong..but I don't like having people telling me I'm wrong for something, when I don't actually think I am Tongue

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy.] Replace '&' with 'and' in titles In reply to
>>
Is it me, or does he specifically say he wants to replace ALL &'s with the word 'and', not the other way, as you are saying Paul ;)
<<

No thats the opposite of what I was saying you must have misread my post or something.

Lets look at what I said:

Quote:
Mmm & isn't being submitted into the database anyway..."and" is

I said "and" is being inserted in to the database which is what Philip asked for...get rid of &, replace with "and"

&amp; isn't required whether you are replacing & with and or vice versa.

Last edited by:

Paul: Apr 24, 2002, 6:32 AM
Quote Reply
Re: [Paul] Replace '&' with 'and' in titles In reply to
Thanks ALL! I never expected to see so many replies and discussions on this topic when I got up this morning..... fantastic!

Thanks for the statement Paul, SQL is becoming less mysterious to me every day.SmileSmileSmile

Ian. (who's phillip?) just kidding, I always get a kick when you veterans are discussing back and forth.

THANKS AGAIN

Last edited by:

sooke: Apr 24, 2002, 8:58 AM
Quote Reply
Re: [sooke] Replace '&' with 'and' in titles In reply to
Hmm thats too weird, I could have sworn "sponge" had asked the question...thats why I said "Philip" above...hmmm. I must need glasses :)

Last edited by:

Paul: Apr 24, 2002, 8:55 AM
Quote Reply
Re: [Wil] Replace '&' with 'and' in titles In reply to
Quote:
Are you sure of the syntax of your previous message? The following page doesn't match up with what the code you supplied:

http://www.mysql.com/doc/R/E/REPLACE.html

That's the wrong REPLACE, Paul's using the replace() function, not the REPLACE sql statement. See:

http://www.mysql.com/...tring_functions.html

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Replace '&' with 'and' in titles In reply to
Aha. Thanks for the clarification.

On a seperate note; why does [quote] take out the URL markup?

Cheers

- wil
Quote Reply
Re: [Wil] Replace '&' with 'and' in titles In reply to
In my post it didn't because I was using mozilla and the regular editor and it didn't auto link up the URL like IE does.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Replace '&' with 'and' in titles In reply to
OK. I was referring to why it would strip [url] tag from the OP. Never mind!

- wil