Hi.
I have a client database that has been input into by a few different people. Some have used upper case, some lower. I want to run an SQL script to change everything to Title case - i.e. JOE BLOGGS to become Joe Bloggs
I have a script that will do this for a pre-defined value of a variable;
declare @old_str AS varchar(255)
declare @new_str AS varchar(255)
declare @currchar_id AS int
declare @prevchar_id AS int
select @old_str='THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'
select @new_str=''
select @currchar_id=0
select @prevchar_id=0
select @currchar_id=0
select @prevchar_id=0
while(@currchar_id < len(@old_str))
begin
select @currchar_id = @currchar_id + 1
select @new_str =
case (substring(@old_str,@prevchar_id,1))
when char(32) then (@new_str+upper(substring(@old_str,@currchar_id,1)))
else (@new_str+lower(substring(@old_str,@currchar_id,1)))
end
select @prevchar_id = @prevchar_id + 1
end
select @new_str
Can someone tell me how I can use this to update the contents of a field throughout an entire table ?
I have a client database that has been input into by a few different people. Some have used upper case, some lower. I want to run an SQL script to change everything to Title case - i.e. JOE BLOGGS to become Joe Bloggs
I have a script that will do this for a pre-defined value of a variable;
declare @old_str AS varchar(255)
declare @new_str AS varchar(255)
declare @currchar_id AS int
declare @prevchar_id AS int
select @old_str='THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'
select @new_str=''
select @currchar_id=0
select @prevchar_id=0
select @currchar_id=0
select @prevchar_id=0
while(@currchar_id < len(@old_str))
begin
select @currchar_id = @currchar_id + 1
select @new_str =
case (substring(@old_str,@prevchar_id,1))
when char(32) then (@new_str+upper(substring(@old_str,@currchar_id,1)))
else (@new_str+lower(substring(@old_str,@currchar_id,1)))
end
select @prevchar_id = @prevchar_id + 1
end
select @new_str
Can someone tell me how I can use this to update the contents of a field throughout an entire table ?