SQL Upper and Lower Fucntions

The SQL UPPER Function is used to Convert the given Text or expression into Uppercase. The SQL LOWER Function is used to Converts a given expression 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 Server 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 example. For this UPPER and LOWER functions demo, we are going to use the below-shown data

SQL Upper and Lower Function 1

SQL Upper Function for uppercase Example

If you observe the above screenshot, [FirstName] and [LastName] column text was in the Upper case, but [Education] and [Profession] Column values are in 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 [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 Lower Function, let us convert the remaining columns to Lower case.

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

Combining Lower and Upper Functions

In this example, we will show you how to combine the 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 SQL Server Query will convert the [FirstName] and [LastName] column values to Lower case and [Education] and [Profession] Column values to Upper case.

SQL Upper and Lower Function 2

SQL Upper and Lower Functions on Variable

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

DECLARE @Lower2 VARCHAR(20), @Upper2 VARCHAR(20) 
SET @Lower2 = 'Sql Lower Function'
SET @Upper2 = 'SQL Upper FunctioN'
SELECT LOWER('SQL LOWER FUNCTION') AS Lower1 
      ,LOWER(@Lower2) AS Lower2
      ,UPPER('sql upper function')  AS UPPER1
      ,UPPER(@Upper2) AS UPPER2
SQL Upper and Lower Function 3