Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Proper Capitalization Problem in Text Field.
Message
 
 
À
04/12/2006 14:17:18
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01174698
Message ID:
01174735
Vues:
10
>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--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform