UPPER() function in SQL Server
Last Updated :
30 Aug, 2024
The UPPER() function in SQL Server is a useful tool for converting all characters in a string to uppercase. This function is essential for ensuring uniform text formatting and for performing case-insensitive comparisons.
In this article, We will learn about the UPPER() function in SQL Server by understanding various examples and so on.
UPPER() function in SQL Server
- The
UPPER()
function in SQL Server is used to convert a string to uppercase.
- It transforms all the characters in the specified string to their uppercase equivalents
Syntax:
UPPER( string)
Parameters:
- str: The string expression or column that you want to convert to uppercase.
Result:
This function will return the uppercase string.
Example of UPPER() function in SQL Server
Example 1
Let's Convert the string '
be patience be awake'
to uppercase using SQL Server's UPPER()
function to standardize the text format.
SELECT UPPER('be patience be awake')
As New;
Output:
Example 2
Let's Convert the string 'EvERy DAy iS A NEW day
'
to uppercase using SQL Server's UPPER()
function to ensure all characters are in uppercase.
SELECT UPPER('EvERy DAy iS A NEW day')
As New;
Output:
New |
EVERY DAY IS A NEW DAY |
Example 3
Let use the UPPER() function in the SQL table for better understanding and so on.
Create table Players
(
Firstname varchar(40),
Lastname varchar(40),
Country varchar(40)
)
Inserting data into players :
Insert into Players values
('Kane', 'Williamson', 'New Zealand')
The table will look like:
Firstname | Lastname | Country |
---|
Kane | Williamson | New Zealand |
Query Using UPPER() function
Let's Retrieve a list of players from the Players
table, displaying their Firstname
, their Lastname
converted to uppercase as New_name
, and their Country
.
SELECT Firstname,
UPPER(Lastname) As New_name,
Country
FROM Players;
Output:
Firstname | New_name | Country |
---|
Kane | WILLIAMSON | New Zealand |
Example 4
Let's Declare a variable @text
with the value 'be happy be light '
, then convert this variables content to uppercase using SQL Server's UPPER()
function and display both the original and the uppercase versions.
DECLARE @text VARCHAR(45);
SET @text = 'be happy be light ';
SELECT @text,
UPPER(@text) AS Upper;
Output:
Here is the table format for the given data:
Text Value | Upper |
---|
be happy be light | BE HAPPY BE LIGHT |
Conclusion
The UPPER()
function is a straightforward yet effective way to standardize text data in SQL Server. Whether you're dealing with static strings, variables, or data retrieved from tables, converting text to uppercase ensures uniformity and consistency.