Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proper Capitalization Problem in Text Field.
Message
 
 
To
04/12/2006 14:17:18
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01174698
Message ID:
01174735
Views:
8
>I have a table with a varchar field in it. The information in that field is all capitals and I would like to make it normal capitalization. Just like the proper function in Fox. I have not been able to find any text function in SQL that will do the same thing. What is the best way to get this done?

See code below. There's also a whole lirary of T-SQL functions in the Download area.
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 @Str = LOWER(@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
Next
Reply
Map
View

Click here to load this message in the networking platform