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
https://forums.phpfreaks.com/topic/110519-solved-replace-statement/
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; 

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..

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.