-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringFunctions_AdvancedSQL.sql
More file actions
36 lines (25 loc) · 1019 Bytes
/
StringFunctions_AdvancedSQL.sql
File metadata and controls
36 lines (25 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- the TRIM function trims space from both sides
SELECT EmployeeID, TRIM(EmployeeID) AS IDTRIM
FROM EmployeeErrors
-- this trims the space on the left side
SELECT EmployeeID, LTRIM(EmployeeID) AS IDTRIM
FROM EmployeeErrors
-- this trims the space on the right side
SELECT EmployeeID , RTRIM(EmployeeID) AS IDTRIM
FROM EmployeeErrors
-- Using Replace
SELECT LastName, REPLACE(LastName,'- Fired', '' ) AS LastNameFixed
FROM EmployeeErrors
-- Using Substring - it selects specific indexes based on the column you choose
SELECT err.firstname,SUBSTRING(err.firstname, 1,3),dem.firstname, SUBSTRING(dem.firstname,1,3)
FROM EmployeeErrors err
join EmployeeDemographics dem
on SUBSTRING(err.firstname, 1, 3) = SUBSTRING(dem.FirstName, 1,3)
-- best to use a substring for more accuracy in such columns related data:-
-- Gender
-- Age
-- DOB
-- Lastname
-- Upper and lower
SELECT FirstName, UPPER(FirstName) AS UpperName , LastName, LOWER(LastName)
FROM EmployeeErrors