------------------------------------------------------------------------
-- John David Ayers ----------------------------------------------------
-- September 24, 2009 --------------------------------------------------
-- SELECT COMMAND 4 ----------------------------------------------------
------------------------------------------------------------------------

SELECT ProductName,
CHARINDEX(' ',ProductName)
FROM Products;

-- Shows X ammount of charactes to the left
SELECT CustLastName,
LEFT(CustlastName, 5)
FROM Customers;

-- Shows X ammount of charactes to the right
SELECT CustLastName,
RIGHT(CustlastName, 5)
FROM Customers;

-- Shows how many characters
SELECT CustLastName,
LEN(CustlastName)
FROM Customers;

-- Shows Characters all lower
SELECT CustLastName,
LOWER(CustlastName)
FROM Customers;

-- Shows Characters all upper
SELECT CustLastName,
UPPER(CustlastName)
FROM Customers;

-- Function
SELECT CustFirstName, CustLastName,
LOWER(LEFT(CustFirstName, 1) + Left(CustLastName, 6)) AS [Customer ID]
FROM Customers;

-- Left Trim
SELECT LTRIM('     Karen')

-- Right Trim
SELECT RTRIM('Karen     ')

-- SubString, Shows X ammount of charactes to the left, starting where
SELECT CustLastName,
SUBSTRING(CustLastName, 1, 4)
FROM Customers;

-- Function
SELECT ProductName,
SUBSTRING(ProductName, 1, CHARINDEX(' ',ProductName)-1)
FROM Products;
