-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9661640
commit 6e675a9
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
6e675a9
There was a problem hiding this comment.
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
6e675a9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wonderful tutorial, thank you