Skip to content

Commit

Permalink
Sample files
Browse files Browse the repository at this point in the history
  • Loading branch information
TexanInParis committed Jun 8, 2016
1 parent 39e1bd6 commit 739381e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
20 changes: 15 additions & 5 deletions Microsoft SQL Server/Chapter 04/Listing 4.009.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
-- Ensure you've run SalesOrdersStructure.sql
-- and SalesOrdersData.sql in the Sample Databases folder
-- in order to run this example.

-- NOTE: Sample table Students does not exist.

CREATE DATABASE StudentsTest;
GO

USE StudentsTest;
GO

CREATE TABLE Students (
StudentID int PRIMARY KEY NOT NULL,
LastName varchar(50),
Expand All @@ -11,9 +18,6 @@ CREATE TABLE Students (
);
GO

USE StudentsTest;
GO

SELECT Students.StudentID, Students.LastName, Students.FirstName,
YEAR(GETDATE()) - YEAR(Students.BirthDate) -
(CASE WHEN MONTH(Students.BirthDate) < MONTH(GETDATE())
Expand All @@ -24,9 +28,15 @@ SELECT Students.StudentID, Students.LastName, Students.FirstName,
THEN 1
ELSE 0 END) AS Age
FROM Students;

GO

-- Dummy USE to free up StudentsTest so it can be deleted.
USE SalesOrdersSample;
GO

DROP DATABASE StudentsTest;

GO

--Similar code using EmpDOB in the Employees table in SalesOrdersSample
-- Ensure you've run SalesOrdersStructure.sql
-- and SalesOrdersData.sql in the Sample Databases folder
Expand Down
4 changes: 2 additions & 2 deletions MySQL/Chapter 02/Listing 2.028.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Listing 2.28 shows how to create an index for case-sensitive RDBMS to allow case-insensitive queries.
-- Listing 2.28 shows how to create an index for case-sensitive RDBMS to allow case-insensitive queries.

Since MySQL Server is case-insensitive, there's no need to have this listing.
-- Because MySQL Server is case-insensitive, there's no need to have this listing.
1 change: 1 addition & 0 deletions MySQL/Chapter 03/Listing 3.005.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Ensure you've run Ch03.20.01Structure.sql
-- and Ch03.20.01Data.sql in the Sample Databases folder
-- in order to run this example.
-- NOTE: MySQL doesn't allow "Dec" as a column name; Used "Decm" instead.

USE Item19Example;

Expand Down
2 changes: 1 addition & 1 deletion MySQL/Chapter 04/Listing 4.007.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- NOTE that these are code snippets that are not executable.

--(Replace a code with a word – two examples.)
-- (Replace a code with a word – two examples.)
CASE Students.Gender WHEN 'M' THEN 'Male' ELSE 'Female' END

CASE Students.Gender
Expand Down
6 changes: 3 additions & 3 deletions MySQL/Chapter 04/Listing 4.008.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- NOTE that some are code snippets that are not executable.

--(Generate a salutation based on gender and marital status.)
-- (Generate a salutation based on gender and marital status.)
CASE WHEN Students.Gender = 'M' THEN 'Mr.'
WHEN Students.MaritalStatus = 'S' THEN 'Ms.'
ELSE 'Mrs.' END

--(Rate sales based by Product on quantity sold.)
-- (Rate sales based by Product on quantity sold.)
Use Salesorderssample;

SELECT Products.ProductNumber, Products.ProductName,
Expand All @@ -27,7 +27,7 @@ CASE WHEN (SELECT SUM(QuantityOrdered)
ELSE 'Excellent' END
FROM Products;

--(Calculate raises based on position.)
-- (Calculate raises based on position.)
CASE Staff.Title
WHEN 'Instructor'
THEN ROUND(Salary * 1.05, 0)
Expand Down
8 changes: 6 additions & 2 deletions MySQL/Chapter 04/Listing 4.009.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
-- Ensure you've run SalesOrdersStructure.sql
-- and SalesOrdersData.sql in the Sample Databases folder
-- in order to run this example.

-- NOTE: Sample table Students does not exist.
CREATE DATABASE StudentsTest;

USE StudentsTest;

CREATE TABLE Students (
StudentID int PRIMARY KEY NOT NULL,
LastName varchar(50),
FirstName varchar(50),
BirthDate date
);

USE StudentsTest;

SELECT Students.StudentID, Students.LastName, Students.FirstName,
YEAR(CURDATE()) - YEAR(Students.BirthDate) -
CASE WHEN MONTH(Students.BirthDate) < MONTH(CURDATE())
Expand Down

0 comments on commit 739381e

Please sign in to comment.