Tip of the Day : Similarities and Differences Between LEN and DATALENGTH Functions

SQL Server Helper - Tip of the Day

Example Uses of the LOWER String Function

The LOWER string function returns a character expression after converting uppercase character data to lowercase.  The syntax of the LOWER string function is as follows:

LOWER ( < character_expression > )

The < character_expression > is an expression of character or binary data.  < character_expression > can be a constant, variable or column and it must be of a data type that is implicitly convertible to VARCHAR; otherwise, the CAST function needs to explicitly convert < character_expression >.

Here are sample uses of the LOWER string function

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

DECLARE @Input                VARCHAR(20) = 'sql server helper'
SELECT CASE WHEN LOWER(@Input) = @Input COLLATE Latin1_General_BIN
            THEN 'Yes'
            ELSE 'No' END AS [IsAllLowerCase]

Usage #2 : Determine if a Character is a Letter of the Alphabet

DECLARE @Input1           CHAR(1)
DECLARE @Input2           CHAR(1)
SET @Input1 = '1'
SET @Input2 = 'A'
            THEN 'Yes'
            ELSE 'No' END AS [IsAlphabet1],
       CASE WHEN ASCII(LOWER(@Input2)) != ASCII(UPPER(@Input2))
            THEN 'Yes'
            ELSE 'No' END AS [IsAlphabet2]
IsAlphabet1   IsAlphabet2
------------  ------------
No            Yes

Back to Tip of the Day List Next Tip