Jshee
Jshee

Reputation: 2686

Easy way to update certain field in database that is upper case?

I am looking to update the field 'prefix' in my course table to just have the FIRST letter capitalized and not the whole prefix.

Is there any easy way to do this is SQL?? Sample Output could look like 'Aadm' in the database for 'prefix'.

My table looks like: enter image description here

Sample rows look like: enter image description here

I have SQL that looks like:

WHERE CONCAT(prefix,code) LIKE '%".  $keywords . "%'");

Is it possible to user LOWER on prefix here?

Upvotes: 0

Views: 237

Answers (1)

Nicola Cossu
Nicola Cossu

Reputation: 56357

select prefix,
concat(upper(substring(prefix,1,1)),substring(lower(prefix) from 2)) as initcap
from course

try it in select form before update your field

if you're looking for prefixes where all chars are upper case use a regexp

where binary(prefix) regexp '^[A-Z]+$' 

EDIT. Update query

update course 
set prefix =
concat(upper(substring(prefix,1,1)),substring(lower(prefix) from 2)) 

Upvotes: 1

Related Questions