Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating a function

Author  Topic 

tadin
Yak Posting Veteran

63 Posts

Posted - 2007-03-19 : 17:20:20
Create a Function call InitCap
accepts 1 parameter of type varchar
returns a varchar
It should only capitalize the first letter of the string passed to it.
Items to watch out for.
a-z not starting the string
The 1st letter is already capitalized

This problems deals with ASCII characters, just wanted to get some insight here.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-03-19 : 17:31:42
Run BOL = Books Online = Sql Server help
look up
- Create Function
- Like
- Upper

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

tadin
Yak Posting Veteran

63 Posts

Posted - 2007-03-19 : 17:52:11
CREATE function INITCAP (@inString varchar(200) )
returns varchar(200)
as
BEGIN
DECLARE @i int, @c char(1),@output varchar(255)
SET @output=LOWER(@inString)
SET @i=2
SET @output=stuff(@output,1,1,UPPER(SUBSTRING(@inString,1,1)))
WHILE @i<=LEN(@inString)
BEGIN
SET @c=SUBSTRING(@inString,@i,1)
IF (@c=' ') OR (@c=',')
IF @i<LEN(@inString)
BEGIN
SET @i=@i+1
SET @output=stuff(@output,@i,1,UPPER(SUBSTRING(@inString,@i,1)))
END
SET @i=@i+1
END
RETURN @output
END

--Function Call

SELECT dbo.initcap(ascii('hello'))


I was wondering how to put the ascii with the function? Can anyone give me some feed back it would gratefull.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-19 : 17:56:30
There already is a InitCap function here at SQLTeam.
Please search.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -