Jump to content

[SOLVED] @#$% Replace statement


Topshed

Recommended Posts

Every now and then I have problems with the REPLACE statement

 

Using phpMyadmin Version  2.10.0.2

 

MySQL version 401

 

Table G

 

Field  'wdrn', CHAR [8] default NULL

 

Sample from wdrn I want to change  "Feb-195 "

 

I have been trying  to replace all instances of '195 '  with '1953' where a condition applies in another field

 

 

UPDATE G Set wdrn = REPLACE(wdrn,'195 ','1953') WHERE chassis LIKE 'Guy Arab II'
// Fails !

UPDATE G Set wdrn = REPLACE(wdrn,'195','1953') WHERE chassis LIKE 'Guy Arab II'
// Works but replaces every instance even when date already has four digits ie: 1951

 

I have just destroyed half a days work because it destroyed all my other dates rather then just the ones with the 3 missing

 

Any help would bevery welcome

 

Thanks

Roy...

Link to comment
Share on other sites

orks but replaces every instance even when date already has four digits ie: 1951

 

Of course it will also replace 1951 with 19531, look at the logic. Does your database actually contain wdrn fields that are '195 ' ? Not likely.

 

You would need something like....

 

UPDATE G Set wdrn = REPLACE(wdrn,'195 ','1953') WHERE chassis LIKE 'Guy Arab II' && LENGTH(wdrm) <= 3; 

Link to comment
Share on other sites

Hmm thank you for that, as you can see I tried that statement but it failed

and did the same with your additions

 

Statement 2 worked (wrongly) but not with the additions, both reported  Affected rows: 0

but showed no errors,

 

UPDATE G Set wdrn = REPLACE(wdrn,'195','1953') WHERE chassis LIKE 'Guy Arab II' && LENGTH(wdrn) <= 3 

 

So I am still in trouble

 

re3egards

Roy..

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.