TSQL to Convert Upper Case to Sentence Case

This is a quick snippet showing how to convert a string to sentence case (first letter capitals and the rest lower case).

CREATE FUNCTION dbo.ConvertStringtoSentenceCase
(@InputString Varchar(max))
RETURNS varchar(max)
as
BEGIN

DECLARE @OutputString varchar(max)

SET @OutputString =  (
upper(substring(@InputString,1,1)) +
	lower(substring(@InputString,2,LEN(@InputString)))
	)

 RETURN @OutputString
END
GO

Execute function like this …

SELECT dbo.ConvertStringtoSentenceCase('Convert This String to Sentence CASE')

A good post here from PinalDave showing how to convert to Title case http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/.

About AussieBICG

Connect with me here https://au.linkedin.com/in/aussiebicg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s