.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get Title Case string in SQL Server

Posted By:Lakhan Pal Garg       Posted Date: June 09, 2010    Points: 10    Category: SQL Query    URL: http://www.dotnetspark.com  

This Snippets will be used to get title case string from given string in any format.


DECLARE @string varchar(MAX),@delimiter varchar(1)
DECLARE @tempString varchar(100)
SET @delimiter=' '
SET @string='my name is lakhan pal garg. i am a b.tech graduate.'
SET @newString =''
DECLARE @start INT, @end INT 
DECLARE @output TABLE(data Varchar(100))
SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)
PRINT @end
WHILE @start <=LEN(@string) 
IF @end = 0 
SET @end = LEN(@string) + 1

SET @tempString=LTRIM(RTRIM(SUBSTRING(@string, @start, @end - @start)))
SET @newString=@newString+ UPPER(SUBSTRING(@tempString,1,1))+LOWER(SUBSTRING(@tempString,2,LEN(@tempString)-1))+' '
SET @start = @end + 1
SET @end = CHARINDEX(@delimiter, @string, @start)

SELECT @newString

Pass Your input string in @string variable. and it will return a title case string.


Lakhan Pal Garg


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend