SQL Upper and Lower Functions

The SQL UPPER Function is used to Convert the given Text or expression into Uppercase, and the LOWER Function converts the word or text into Lowercase.

The syntax of SQL Server Upper Function to convert string to uppercase is

SELECT UPPER (Expression | [Column_Name])
FROM SOurce

The basic syntax of the SQL Lower Function to convert to lowercase is:

SELECT LOWER (Expression | [Column_Name])
FROM SOurce

Let us see how to write LOWER Function and UPPER in SQL Server with an example. For this demo, we are going to use the below-shown data

Table 1

SQL Upper Function for uppercase Example

If you observe the above screenshot, the [FirstName] and [LastName] column text was in the Upper case, but the [Education] and [Profession] Column values were in the Lower case.

It looks tedious when we show the same output to the end user. So, using this Upper Function, let us convert the remaining columns to the upper case.

SELECT [FirstName] 
      ,[LastName] 
      ,[YearlyIncome] 
      ,UPPER([Education]) AS [EDUCATION]
      ,UPPER([Profession]) AS [PROFESSION]
  FROM [Employ]
SQL Upper Function 1

SQL Lower Function for lowercase Example

If you observe the Source Data, [FirstName] and [LastName] column values are in the Upper case. But the [Education] and [Profession] Column data is in Lower case. It looks unprofessional when we show the same output to the end user. So, using this SQL Lower Function, let us convert the remaining columns to Lowercase.

SELECT LOWER([FirstName]) AS [First Name] 
      ,LOWER([LastName]) AS [Last Name] 
      ,[YearlyIncome] 
      ,[Education]
      ,[Profession]
  FROM [Employ]
SQL Lower Function 1

Combining two Functions

In this example, we will show you how to combine the SQL Lower Function and Upper Function in one SELECT Statement.

SELECT LOWER([FirstName]) AS [First Name] 
      ,LOWER([LastName]) AS [Last Name] 
      ,[YearlyIncome] 
      ,UPPER([Education]) AS [EDUCATION]
      ,UPPER([Profession]) AS [PROFESSION]
  FROM [Employ]

Above Server Query will convert the [FirstName] and [LastName] column values to Lower case and the [Education] and [Profession] Column values to Upper case.

UPPER and LOWER Example 2

SQL Upper and Lower Functions on Variable

We can also apply the Upper and Lower function to constant values and Variables.

DECLARE @Lower2 VARCHAR(20), @Upper2 VARCHAR(20) 
SET @Lower2 = 'SqlLower Function'
SET @Upper2 = 'SQLUpper FunctioN'
SELECT LOWER('SQLLOWER FUNCTION') AS Lower1 
      ,LOWER(@Lower2) AS Lower2
      ,UPPER('sqlupper function')  AS UPPER1
      ,UPPER(@Upper2) AS UPPER2
SQL Uppercase and Lowercase 3
Categories SQL