Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tranfer "paul" into "Paul"

Status
Not open for further replies.

payoff12

Technical User
Oct 22, 2003
1
NL
In the database I have a name field which contains name of members. Unfortunately some names are just in lower cast, some in just in upper cast. How can i use sql to pull the data from the database where the first character is uppercast and the other characters are lower cast.

Some examples:
Paul should become Paul
PAUL should become Paul
paul should become Paul

 
You mean you want to update the names? Or select them? The syntax depends on yout DB. In Sybase you could do
Code:
select upper(substring(fieldname,1,1)) + lower(substring(fieldname,2,char_length(fieldname)))
from tablename
To update, you could do
Code:
update tablename
set fieldname = upper(substring(fieldname,1,1)) + lower(substring(fieldname,2,char_length(fieldname)))
from tablename
Greg.
 
You could also use the INITCAP funtion if you database supports it
 
Here is a SQL Server function that I have used to change the first letter in every word in a sentence to upper case. You could modify it to look for the first word after certain punctuation marks if you had multiple sentences.
Code:
CREATE FUNCTION dbo.f_Proper_Case ( @v_IN_String  varchar(8000))
RETURNS VARCHAR(8000) AS  
BEGIN 
DECLARE
 @v_OUT_String     varchar(8000)
 
set @v_IN_String = Lower(@v_IN_String) + ' '
set @v_OUT_String = ''
 
while ( charindex(' ',@v_IN_String,1) > 0)
 begin
      set @v_OUT_String = @v_OUT_String + Upper(left(@v_IN_String,1)) + substring(@v_IN_String,2,charindex(' ',@v_IN_String,1) - 1)
      set @v_IN_String = right(@v_IN_String, len(@v_IN_String) - charindex(' ',@v_IN_String,1) + 1)
 end
 
RETURN( @v_OUT_String )
END

~Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top