SQL LOWER Function | Convert a String Into SQL Lowercase
SQL Lowercase Function Summary: In this article, you will learn What is SQL Server LOWER() function
and How to use the SQL LOWER function to convert all characters of a string into the SQL lowercase.
Definition and Usage
The LOWER() function converts all the characters in a string into lowercase. suppose that if you want to convert all characters in a string into uppercase, then you should use the SQL UPPER function.
In another way, you can say that in SQL Server, you can convert any uppercase string to lowercase by using the SQL LOWER() function.
Therefore, just simply provide the string as an argument when you call the function, and it will be returned in lowercase form.
SQL Lowercase Function Syntax
The following syntax shows the LENGTH() function:
In this syntax:
- Required. the input_string in this syntax can be a literal character string, character string expression, variable, or table column.
The type of the input_string must be implicitly convertible to VARCHAR. Otherwise, you must use the CAST() function to convert the input_string explicitly.
The LOWER() function returns a string with all characters in the lowercase format. if the input string is NULL then its returns NULL.
SQL Server LOWER Function Examples
Let’s take few examples of using the LOWER() function.
A) Using SQL LOWER() function with the literal strings
The following statement uses the SQL Server LOWER function to convert a string to lowercase:
1 |
SELECT LOWER('TUTORIALSCAN'); |
1 2 3 4 |
lower ---------------------- tutorialscan (1 row) |
B) Using SQL LOWERCASE function with table column
The following given below Persons
table to used for demonstration.
PersonID | Name | Address | City |
---|---|---|---|
1 | Noah Elijah | Bridgetown | Barbados |
2 | William Josiah | Brussels | Belgium |
3 | Elijah Connor | Zagreb | Croatia |
4 | Benjamin Hunter | San Jose | Costa Rica |
5 | Alexander Landon | Roseau | Dominica |
6 | Jacob Jonathan | Paris | France |
7 | Daniel Jeremiah | Libreville | Gabon |
8 | Owen Dominic | Athens | Greece |
9 | Gabriel Roman | Tegucigalpa | Honduras |
10 | Mateo Ezekiel | Budapest | Hungary |
The following statement uses the SQL LOWER() function to convert the Name and Address of persons to lowercase before concatenation.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
SELECT Name, Address, CONCAT_WS( ' ', LOWER(Name), ' ', LOWER(Address) ) full_address_lowercase FROM Persons ORDER BY Name; |
C) Using sql Lowercase function to querying data case insensitive
Therefore the literal string “Alexander Landon” is different from the “alexander landon” when it comes to an input for a query because of SQL performing the operation such as case-sensitive.
To query data case-insensitive, then you can use the SQL LOWER() function.
1 2 3 4 5 6 |
SELECT PersonID, Name, Address, City FROM Persons WHERE Name = 'Alexander Landon'; |
However, when you use the SQL Server LOWER function
, it returns a row.
1 2 3 4 5 6 |
SELECT PersonID, Name, Address, City FROM Persons WHERE LOWER(Name) = 'alexander landon'; |
Conclusion
In this tutorial, you have learned What is SQL Server LOWER() function
and How to use this function with different conditions to convert all characters of a string into SQL lowercase. I hope you will enjoy! if have any query, contact me, I have try to resolve the problem.