Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Title Case
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Divers
Thread ID:
01000059
Message ID:
01000069
Vues:
27
>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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform