Change Letter case on products

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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:

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

 

Regards
 
Ben 
OpenVPMS Installer and Helper 
Ph: +61423044823 
Email: info[at]charltonit.com[dot]au

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:

select 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;

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.

 

select count(p.product_id)
from products p
join entities e
on e.entity_id = p.product_id;

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.


begin;
update products p
    join entities e
    on e.entity_id = p.product_id
set e.name = concat(substring(e.name, 1, 1), lower(substring(e.name, 2)));

 

These two statements perform the update in a transaction. You will see something like:

841 row(s) affected Rows matched: 890  Changed: 841  Warnings: 0    0.016 s

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:

select p.product_id, e.name
from products p
join entities e
on e.entity_id = p.product_id
order by e.name;

to verify that the products were updated correctly.

If you aren't happy with the results, run:

rollback;

to discard the update.

Otherwise run:

commit;

to make them permanent.

 

Re: Change Letter case on products

This worked! thanks alot Ben and Tim

 

Syndicate content