Convert String to Sentence Case Script | Database Journal

Convert String to Sentence Case Script

Aug 10, 2002
1 minute read


This small function from Subhan Munshi converts a submitted string to sentence case.


CREATE FUNCTION fn_ToSentenceCase (@inputstr as varchar(1000))
RETURNS varchar(1000)
AS
BEGIN
	--Author: Subhan Munshi
	declare @Upper as char(1)
	declare @len as int
	declare @count as int
	declare @flag bit
	declare @resultstr varchar(100)
	
	set @len = len(@inputstr)
	set @count = 2
	set @resultstr = upper(left(@inputstr,1))
	while @count <= @len
	begin	
		select @Upper = substring(@inputstr,@count-1,1)
		if @Upper = ' '
			set @flag = 1
		else
			set @flag = 0
	
		if @flag = 1
			select @resultstr = @resultstr + upper(substring(@inputstr,@count,1))
		else
			select @resultstr = @resultstr + lower(substring(@inputstr,@count,1))
		set @count = @count + 1 
	end 	
	
	RETURN (@resultstr)
END
Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.