SQL Scalar-valued Function – Capitalize the first character

It’s simple, it’s basic, it spans across 16 lines of T-SQL code (including breaklines)….and you might need it someday 🙂


CREATE FUNCTION [dbo].[fn_TextToInitCase]
(
@VarString NVARCHAR(250)
)
RETURNS NVARCHAR(250)
AS
BEGIN

DECLARE
@Result NVARCHAR(250)

SET @Result = UPPER(SUBSTRING(@VarString,1,1))+SUBSTRING(@VarString,2,LEN(@VarString))

RETURN @Result

END

Advertisements

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