For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > August 2007 > mySql - find and replace.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author mySql - find and replace.
Richard

2007-08-21, 8:01 am

Hi there.
Am a total newbie to sql language.

Does mySql have a find and replace function
or can a command be written to perform such
a task.

In the table I have a column named MEDAL_NAME

I wish to change all entries in that colum that
contain the words "War Plaque" to "Memorial Plaque"

Any pointers gratefully received


Richard

2007-08-21, 8:01 am

underprocessable
Rik

2007-08-21, 8:01 am

On Tue, 21 Aug 2007 14:00:32 +0200, Richard <sales@justmedals.com> wrote=
:

>
> I have tried:
> UPDATE [LISTINGS] SET [MEDAL_NAME] =3D replace( [MEDAL_NAME], '[War =


> Plaque]',
> '[Memorial Plaque]' )
>
> MySQL said:
>
> #1064 - You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use n=

ear
> '[LISTINGS] set [MEDAL_NAME] =3D replace([MEDAL_NAME],'[War
> Plaque]','[Memorial Pla' at line 1
>
> ????????


I assume the blockquotes aren't there...

UPDATE `LISTINGS` SET `MEDAL_NAME` =3D REPLACE(`MEDAL_NAME`, 'War =

Plaque','Memorial Plaque')

(Are you sure the tablename & fielname are all in capitals? Default woul=
d =

be lowercase AFAIK).
-- =

Rik Wasmus
Geoff

2007-08-21, 8:01 am


"Richard" <sales@justmedals.com> wrote in message
news:hmAyi.23818$ie3.23309@newsfe3-gui.ntli.net...
> Hi there.
> Am a total newbie to sql language.
>
> Does mySql have a find and replace function
> or can a command be written to perform such
> a task.
>
> In the table I have a column named MEDAL_NAME
>
> I wish to change all entries in that colum that
> contain the words "War Plaque" to "Memorial Plaque"
>
> Any pointers gratefully received
>
>


http://www.w3schools.com/sql/sql_update.asp
UPDATE table_name
SET column_name = new_value
WHERE column_name = some_valuesomething like the above will dothat site is
quite handy when starting out i found


Richard

2007-08-21, 8:01 am

OK Corrected the syntax - see below

"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:op.txeskv0rqnv3q9@metallium...
On Tue, 21 Aug 2007 14:00:32 +0200, Richard <sales@justmedals.com> wrote:

>
> I have tried:
> UPDATE [LISTINGS] SET [MEDAL_NAME] = replace( [MEDAL_NAME], '[War
> Plaque]',
> '[Memorial Plaque]' )
>
> MySQL said:
>
> #1064 - You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use near
> '[LISTINGS] set [MEDAL_NAME] = replace([MEDAL_NAME],'[War
> Plaque]','[Memorial Pla' at line 1
>
> ????????


I assume the blockquotes aren't there...

UPDATE `LISTINGS` SET `MEDAL_NAME` = REPLACE(`MEDAL_NAME`, 'War
Plaque','Memorial Plaque')

(Are you sure the tablename & fielname are all in capitals? Default would
be lowercase AFAIK).
--
Rik Wasmus

Should Be:

UPDATE `LISTINGS` SET `MEDAL_NAME` = REPLACE(`MEDAL_NAME`, "War
Plaque","Memorial Plaque")

Changed to double commas and it carried out the order!! Thanks all


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com