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.
SPACE Function
The SPACE function is an equivalent of using REPLICATE to repeat spaces. This function takes a single argument - number of spaces you want to print.
UPPER and LOWER Functions
UPPER and LOWER functions change the case of the query's output. Both functions accept a string expression as the only argument. For example, the following query will return the US cities and corresponding states in mixed case:
SELECT UPPER(LEFT(City, 1)) + LOWER(SUBSTRING(City, 2, (LEN(City) - 1))) + ',' + SPACE(2)
+ UPPER(LEFT(StateProvinceName, 1)) + LOWER(SUBSTRING(StateProvinceName, 2,
(LEN(StateProvinceName) - 1))) AS CityAndState
FROM DimGeography WHERE CountryRegionCode = 'us'
Results (abbreviated):
CityAndState
Chandler, Arizona
Gilbert, Arizona
Mesa, Arizona
Phoenix, Arizona
Scottsdale, Arizona
Tags:
SQL Server string functions are scalar functions that perform an operation on a string input value and return a string or numeric value.
The SPACE function is an equivalent of using REPLICATE to repeat spaces. This function takes a single argument - number of spaces you want to print.
UPPER and LOWER Functions
UPPER and LOWER functions change the case of the query's output. Both functions accept a string expression as the only argument. For example, the following query will return the US cities and corresponding states in mixed case:
SELECT UPPER(LEFT(City, 1)) + LOWER(SUBSTRING(City, 2, (LEN(City) - 1))) + ',' + SPACE(2)
+ UPPER(LEFT(StateProvinceName, 1)) + LOWER(SUBSTRING(StateProvinceName, 2,
(LEN(StateProvinceName) - 1))) AS CityAndState
FROM DimGeography WHERE CountryRegionCode = 'us'
Results (abbreviated):
CityAndState
Chandler, Arizona
Gilbert, Arizona
Mesa, Arizona
Phoenix, Arizona
Scottsdale, Arizona