Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help with writing and SQL statement


NodsDorf

Recommended Posts

Posted

I need to replace part of some our part numbers in our database from -70N to -75N there are about 800 changes needed to be made. I was hoping I could do this with an SQL statement to modify the database. The problem is that the -70N is the end of the string of the part number so the numbers are actually like AS568-001-70N... how can I make it so the SQL just changes the -70N to -75N?

 

 

Is there a way to do this in SQL ?

 

I've tried the best I could with what I know

Select products where products_model like '-75N'

 

Once I can select them should I then be able to just do a replace (update) or something?

 

I could use any help.

 

 

Thank you,

Don

Posted

I was thinking something like this, but could a guru please confirm before I go wild.

 

SELECT products_model From products REPLACE('*','-70N','-75N');

Posted

I was thinking something like this,

 

SELECT products_model From products REPLACE('*','-70N','-75N');

I'm not pretending to be a guru but with a little help from Google this seems to work fine in a test (the regular expression looks for -70N at the end of the products_model field)

 

update products set products_model = replace(products_model, '-70N', '-75N') where products_model REGEXP '-70N$';

I would suggest making a backup of that table before you try this :)

Posted

another approach would be use complete php code, which btw is what i would do most of time. you could echo the records for examination before actually writing them (after updating them) back to the db. dont over done it though, eg, creating classes/functions:D. about 10 lines of php code would get it done.

Ken

commercial support - unProtected channel, not to be confused with the forum with same name - open to everyone who need some professional help: either PM/email me, or go to my website (URL can be found in my profile).

over 20 years of computer programming experience.

Archived

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

×
×
  • Create New...