SQL Server String Functions
SQL Server string functions are scalar functions that perform an operation on a string input value and return a string or numeric value.
LEFT Function
Transact-SQL supports retrieving portions of the string. For instance, to retrieve the first few characters from the left of the string you use the LEFT function. The following example retrieves first four letters of employee last names in the AdventureWorksDW database:
SELECT LEFT(LastName, 4) AS FirstFourLettersOfLastName, LastName FROM dbo.DimEmployee
Results (abbreviated):
FirstFourLettersOfLastName
Gilb
Brow
Tamb
Walt
Walt
RIGHT Function
The RIGHT function retrieves the portion of the string counting from the right. For example:
SELECT RIGHT(LastName, 4) AS FirstFourLettersOfLastName, LastName as FullLastName FROM dbo.DimEmployee
Results:
LastFourLettersOfLastName FullLastName
bert Gilbert
rown Brown
ello Tamburello
ters Walters
ters Walters
Tags: SQL String Functions Sql Server MySql SQL Server String Functions LEFT RIGHT.
SQL Server string functions are scalar functions that perform an operation on a string input value and return a string or numeric value.
LEFT Function
Transact-SQL supports retrieving portions of the string. For instance, to retrieve the first few characters from the left of the string you use the LEFT function. The following example retrieves first four letters of employee last names in the AdventureWorksDW database:
SELECT LEFT(LastName, 4) AS FirstFourLettersOfLastName, LastName FROM dbo.DimEmployee
Results (abbreviated):
FirstFourLettersOfLastName
Gilb
Brow
Tamb
Walt
Walt
RIGHT Function
The RIGHT function retrieves the portion of the string counting from the right. For example:
SELECT RIGHT(LastName, 4) AS FirstFourLettersOfLastName, LastName as FullLastName FROM dbo.DimEmployee
Results:
LastFourLettersOfLastName FullLastName
bert Gilbert
rown Brown
ello Tamburello
ters Walters
ters Walters