Change Letter case on products
Submitted by david_cloudegic on Tue, 02/06/2020 - 18:33
How can i change the products names to only start with Capital letter, we copy-pasted the products in the system, all with capital letters. e.g. BILATERAL ENTROPIUM CORRECTION
Is there a way to filter all of them and change the case?
Thanks
Re: Change Letter case on products
Only by writing SQL to update the database directly.
As an example, here's a select statement to lowercase everything but the first character:
Re: Change Letter case on products
How do i effect the changes in the database?
Re: Change Letter case on products
Am getting this error;
ERROR 1064 (42000): 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 '(subs
tring(e.name, 1, 1), lower(substring(e.name, 2)))
from products p
join enti' at line 1
Re: Change Letter case on products
INSERT INTO p.product_id, concat(substring(e.name, 1, 1), lower(substring(e.name, 2)))
from products p
join entities e
on e.entity_id = p.product_id
order by e.name;
Re: Change Letter case on products
How do i write SQL to update the database directly.
Am stuck
Help
Re: Change Letter case on products
My advice is download Mysql Workbench it will step you through writing SQL code and error check your sql.
Tim gave you a select statement to retrieve the entries. But you're going to need to write the result of that to a temp table and then do an update statement to update the information in the database.
Re: Change Letter case on products
Before doing any database changes, you should back up your database, and test any changes in a test system first. If you make a mistake you can revert to the backup.
First, verify you are updating the right things:
This statement will show a listing of the product ids and what their updated names will look like. Note that products with multiple words will have subsequent words lowercased. E.g.
AMOXIL SYRUP FORTE 50MG/ML -> Amoxil syrup forte 50mg/ml
If you don't want this, you'll probably have to write a stored procedure to do it.
This statement will count the maximum number of rows that will be updated. It is an upper bound - your actual update may change fewer rows as they might already have the correct case.
In my database, it shows 890.
These two statements perform the update in a transaction. You will see something like:
In the above, 841 of the 890 rows were changed, because 49 already had the correct case.
Before you commit the changes, you can run:
to verify that the products were updated correctly.
If you aren't happy with the results, run:
to discard the update.
Otherwise run:
to make them permanent.
Re: Change Letter case on products
This worked! thanks alot Ben and Tim