Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Title Case
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Miscellaneous
Thread ID:
01000059
Message ID:
01000069
Views:
36
>Before I spend a couple hours pounding this out, is there anyone out there that has a T-SQL function that converts a string to Title Case?
>
>For example
>
>"this is a text string" would be converted to "This Is A Test String"
>
IF EXISTS (SELECT * 
	   FROM   sysobjects 
	   WHERE  name = N'ufn_Proper')
	DROP FUNCTION ufn_Proper
GO

CREATE FUNCTION ufn_Proper 
	(@Str varchar(8000), 
	 @Delimiters varchar(12)= ' ') 
RETURNS varchar(8000)
AS
BEGIN
	DECLARE @Pos int, @CharIsDelimiter char(1), @StrLen int

SET @CharIsDelimiter = 'Y'
SET @StrLen = LEN(@str)
SET @pos = 1
WHILE @pos <= @StrLen
BEGIN
	IF CHARINDEX(SUBSTRING(@Str, @pos, 1), @Delimiters) > 0
		SET @CharIsDelimiter = 'Y'
	ELSE
	IF @CharIsDelimiter = 'Y'
	BEGIN 
		SET @Str = STUFF(@Str, @pos, 1, UPPER(SUBSTRING(@Str, @pos, 1)))
		SET @CharIsDelimiter = 'N'
	END
	SET @pos = @pos + 1
END	
RETURN @Str
END
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform