Applying various string functions on data
As you may have noticed, string functions are really useful for manipulating data. SQL Server offers a lot of built-in functions for string manipulation and some of them are quite fun to use.
In this exercise, you are going to apply several string functions to the data from the voters
table, to show it in a more presentable manner.
You will get the chance to use functions like: LEN()
, UPPER()
, PATINDEX()
, CONCAT()
, REPLACE()
and SUBSTRING()
.
Remember: when searching for patterns within a string, these are the most helpful:
pattern | match |
---|---|
% | any string of zero or more characters |
_ | any single character |
[] | any single character within the range specified in brackets |
This exercise is part of the course
Functions for Manipulating Data in SQL Server
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT
first_name,
last_name,
birthdate,
email,
country
FROM voters
-- Select only voters with a first name less than 5 characters
WHERE ___(___) < 5
-- Look for the desired pattern in the email address
AND ___(___, ___) > 0;