If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > From upper cse to lower case

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-29-04, 12:37
JohnStrecker JohnStrecker is offline
Registered User
 
Join Date: Sep 2004
Posts: 39
Cool From upper cse to lower case

Hi all

I have a "countries" table in which a Country_name field has all country names in upper case.

Rather than retyping them all, which SQL statement will keep the first letter in upper case and put the rest in lower case?

Please

Many thanks in advance

John in Belgium
Reply With Quote
  #2 (permalink)  
Old 09-29-04, 12:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
update countries
set Country_name
= concat(upper(left(Country_name,1))
,lower(substring(Country_name from 2 to length(Country_name)-1)))

then manually update any names that are more than one word, e.g. Costa rica
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-29-04, 14:50
JohnStrecker JohnStrecker is offline
Registered User
 
Join Date: Sep 2004
Posts: 39
Hi Rudy

Thank you for your suggestion. Alas it crashed.

I got an error message saying

#1064 - You have an error in your SQL syntax.

I tried the various parts in a select statement and they worked until I boiled it down to

SELECT substring( Country_name
FROM 2 to 6 )
FROM countries

which seems to be the bit that causes the problem. (I used '6' just to check)

Any suggestion?
Reply With Quote
  #4 (permalink)  
Old 09-29-04, 14:55
JohnStrecker JohnStrecker is offline
Registered User
 
Join Date: Sep 2004
Posts: 39
Hi again (continued)

but then I got an inspiration from your suggestion and I used

update countries
set Country_name
= concat(upper(left(Country_name,1))
,lower(right(Country_name,length(Country_name)-1)))

and this one worked perfectly well

Thanks again!
Reply With Quote
  #5 (permalink)  
Old 09-29-04, 14:56
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
doh!!

my bad

the syntax is SUBSTRING(str FROM pos FOR len)

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 09-29-04, 18:58
JohnStrecker JohnStrecker is offline
Registered User
 
Join Date: Sep 2004
Posts: 39
I am affraid that one

SELECT substr( country_name FROM 2 FOR 6 ) FROM countries

generated an error message as well ... )
Reply With Quote
  #7 (permalink)  
Old 09-29-04, 19:30
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
let me guess, the error was... um, hold on, i've almost got it...

nope, my crystal ball isn't working

i can't seem to guess what the error might be

you didn't by any chance abbreviate the function name, did you?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 09-30-04, 03:34
JohnStrecker JohnStrecker is offline
Registered User
 
Join Date: Sep 2004
Posts: 39
Hi and thanks for your continued interest )

When I use your

the syntax is SUBSTRING(str FROM pos FOR len) in other words

select substr(country_name from 2 for 6) from countries

it crashes.

Or put otherwise, how do I select the caracters in a country_name field starting from the second one using the substr() function?

Have fun day
Reply With Quote
  #9 (permalink)  
Old 09-30-04, 04:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
the function is substring, not substr

you abbreviated it!!
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 09-30-04, 13:24
JohnStrecker JohnStrecker is offline
Registered User
 
Join Date: Sep 2004
Posts: 39
Quote:
Originally Posted by r937
the function is substring, not substr

you abbreviated it!!

Aaaaarrghhhhh "All ye who did Ashton Tate dBase code lines ,for 15 years in truth I tell you ye are all doomed!"

It worked! Thanks

Have a fun day !

Best from Belgium
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On