Tip of the Day : Example Uses of the UPPER String Function

Welcome to SQL Server Helper !!!

This site is intended for those who are beginning to use SQL Server as part of their day-to-day activities.  You will find in this site a collection of useful functions, triggers, stored procedures and tips and tricks related to SQL Server.

Should you have any comments or questions regarding this site or if you want to ask SQL Server-related questions, e-mail us here.

We hope we are able to help and we are glad to help!!!

SQL Server Tip of the Day - September 16, 2019

Example Uses of the UPPER String Function

The UPPER string function returns a character expression with lowercase character data converted to uppercase. The syntax of the UPPER string function is as follows:

UPPER ( <character_expression> )

The <character_expession> parameter of the UPPER string function is an expression of character data which can be a constant, variable, or column of either character or binary data.  It must be of a data type that is implicitly convertible to VARCHAR data type.

Here are a few examples on the uses of the UPPER string function:

Usage #1 : Determine if All Characters in a String are in Upper Case

DECLARE @Input			VARCHAR(20) = 'SQL SERVER HELPER'

SELECT CASE WHEN UPPER(@Input) = @Input COLLATE Latin1_General_BIN
            THEN 'Yes'
            ELSE 'No' END AS [IsAllUpperCase]

Usage #2 : Format a String into Proper Case / Title Case (Equivalent to Oracle’s INITCAP Function)

DECLARE @Input			VARCHAR(100) = 'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'

SET @Input = STUFF(LOWER(@Input), 1, 1, UPPER(LEFT(@Input, 1)))
SELECT @Input = REPLACE(@Input, SUBSTRING(@Input, [Number], 2), 
				CASE WHEN SUBSTRING(@Input, [Number], 2) LIKE ' %'
					 THEN UPPER(SUBSTRING(@Input, [Number], 2))
					 ELSE SUBSTRING(@Input, [Number], 2) END)
FROM [master].[dbo].[spt_values]
WHERE [Type] = 'P' AND [Number] != 0 AND [Number] <= LEN(@Input)

SELECT @Input AS [InitCap]
InitCap
-----------------------------------------------
The Quick Brown Fox Jumps Over The Lazy Dog

SQL Server 2012

SQL Server 2008

User-Defined Functions

Date Functions

A collection of useful user-defined functions that deal with dates.

String Functions

A collection of useful user-defined functions that deal with strings (varchar/char/nvarchar/nchar).

Tree Functions

A collection of useful user-defined functions that deal with tree or hierarchical design structures.

Table-Valued Functions

A collection of useful table-valued user-defined functions that can be used to join with other tables.

SQL Server Built-in Functions

A reference to all built-in functions available within SQL Server grouped into categories.

Tips and Tricks

A collection of useful SQL Server-related tips and tricks:

SQL Server Error Messages

A list of SQL Server error messages and for certain error messages, discusses ways on how to solve the error or work around them:

Frequently Asked Questions