Hints And Tips research knowledge archive
Tip# 148
Sponsored Links
 
Subject: First letter caps function for SQL Server 2000
Updated: Sep-6-2004
Rating: Not Rated
By: Rocky Moore - Member #: 461
Location: Klamath Falls, Oregon USA
Website: www.ReflectedThought.com
Category: Computers > Programming > Databases
Rate This Tip (10=Great):  1  2  3  4  5  6  7  8  9  10
I recently pulled in a table of zipcodes from an external source.  Everything was in caps and I wanted the data formatted with the first letter of each word to be in caps.  After a bit of digging around the net, I found this function somewhere that can help:

CREATE function FirstCaps(@textValue varchar(7999))
returns varchar(7999)
as
begin
declare @workText varchar(8000)
declare @newtxt varchar(8000), @startpos int,  @nextpos int
set @workText = @textValue+' ';
select @startpos = 1  -- starting position
select @nextpos = CharIndex( ' ', @workText, @startpos)
Select @newtxt = ''

while @startpos <> 0 and @nextpos <> 0
begin
  set @newTxt = @newTxt  + upper(substring(@workText, @startpos,1)) +
    Lower(substring(@workText, @startpos +1, @nextpos - @startpos))
  set @Startpos = @nextpos + 1
  set @nextpos = charIndex( ' ', @workText,@startpos )
end

return @newtxt
end


It is a bit crude, but works for what I needed!

[Submit DIGG for this tip]


-----------
Note: Use the tips posted on this site at your own risk. The tips are posted by the public and as such may or may not be valid.

Sponsored Links
     
Categories
hints and tips gold divider
Sponsor Sites To Visit
www.SaintsInLight.com
Thoughts on the Christian walk
along various Christian links.

CICK HERE
www.BringingInTheHarvest.com
Christian:  The harvest is ripe and
the day is short, we need to bring in
the harvest while there is time!

CLICK HERE
XML RSS News Feed For Recently Posted Hints And Tips  RSS Feed
You can now get updates to the Recent Tips section by using RSS. The address is:

HintsAndTips.com/Rss.aspx

* Posting Tips *
To post a Tip, Recommendation or Tips Wanted, simply browse to the category you feel is a best fit for your post (click on the Recommention or Tips Wanted tab if fitting) and then click on "New Post" option.
(C) Copyright 1998-2010 All Rights Reserved