Skip to content

Commit

Permalink
String Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTheAnalyst authored Feb 3, 2021
1 parent 9661640 commit 6e675a9
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions String Functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*

Today's Topic: String Functions - TRIM, LTRIM, RTRIM, Replace, Substring, Upper, Lower

*/

--Drop Table EmployeeErrors;


CREATE TABLE EmployeeErrors (
EmployeeID varchar(50)
,FirstName varchar(50)
,LastName varchar(50)
)

Insert into EmployeeErrors Values
('1001 ', 'Jimbo', 'Halbert')
,(' 1002', 'Pamela', 'Beasely')
,('1005', 'TOby', 'Flenderson - Fired')

Select *
From EmployeeErrors

-- Using Trim, LTRIM, RTRIM

Select EmployeeID, TRIM(employeeID) AS IDTRIM
FROM EmployeeErrors

Select EmployeeID, RTRIM(employeeID) as IDRTRIM
FROM EmployeeErrors

Select EmployeeID, LTRIM(employeeID) as IDLTRIM
FROM EmployeeErrors





-- Using Replace

Select LastName, REPLACE(LastName, '- Fired', '') as LastNameFixed
FROM EmployeeErrors


-- Using Substring

Select Substring(err.FirstName,1,3), Substring(dem.FirstName,1,3), Substring(err.LastName,1,3), Substring(dem.LastName,1,3)
FROM EmployeeErrors err
JOIN EmployeeDemographics dem
on Substring(err.FirstName,1,3) = Substring(dem.FirstName,1,3)
and Substring(err.LastName,1,3) = Substring(dem.LastName,1,3)



-- Using UPPER and lower

Select firstname, LOWER(firstname)
from EmployeeErrors

Select Firstname, UPPER(FirstName)
from EmployeeErrors

2 comments on commit 6e675a9

@Kaystevee
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really make your tutorials easier

@GraphicsLan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonderful tutorial, thank you

Please sign in to comment.