Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 16, 2016
0 parents commit 5392963
Show file tree
Hide file tree
Showing 35 changed files with 10,344 additions and 0 deletions.
Binary file added 9781430242000.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2012 Jason Brimhall, David Dye, Timothy Roberts, Wayne Sheffield, Jonathan Gennick, and Joseph Sack

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
#Apress Source Code

This repository accompanies [*SQL Server 2012 T-SQL Recipes*](http://www.apress.com/9781430242000) by Jason Brimhall, David Dye, Timothy Roberts, Wayne Sheffield, Jonathan Gennick, and Joseph Sack (Apress, 2012).

![Cover image](9781430242000.jpg)

Download the files as a zip using the green button, or clone the repository to your machine using Git.

##Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

##Contributions

See the file Contributing.md for more information on how you can contribute to this repository.
9 changes: 9 additions & 0 deletions ReadMe.txt
@@ -0,0 +1,9 @@
Welcome! You have just opened the ReadMe file for the example source code archive for the following book:

SQL Server 2012 T-SQL Recipes
by Jason Brimhall, David Dye, Timothy Roberts, Wayne Sheffield, Jonathan Gennick
978-1430242000

Source code is organized in .sql files by chapter. For example, the solution snippets from chapter 1 are in the file ch01.sql.

Enjoy the examples!
163 changes: 163 additions & 0 deletions ch01.sql
@@ -0,0 +1,163 @@
1.1. Connecting to a Database

USE AdventureWorks2008R2;


1.2. Retrieving Specific Columns

SELECT NationalIDNumber,
LoginID,
JobTitle
FROM HumanResources.Employee;


1.3. Retrieving All Columns

SELECT *
FROM HumanResources.Employee;


1.4. Specifying Rows to Be Returned

SELECT Title,
FirstName,
LastName
FROM Person.Person
WHERE Title = 'Ms.';

SELECT Title,
FirstName,
LastName
FROM Person.Person
WHERE Title = 'Ms.' AND
LastName = 'Antrim';


1.5. Renaming the Output Columns

SELECT BusinessEntityID AS "Employee ID",
VacationHours AS "Vacation",
SickLeaveHours AS "Sick Time"
FROM HumanResources.Employee;


1.6. Building a Column from an Expression

SELECT BusinessEntityID AS EmployeeID,
VacationHours + SickLeaveHours AS AvailableTimeOff
FROM HumanResources.Employee;


1.7. Providing Shorthand Names for Tables

SELECT E.BusinessEntityID AS "Employee ID",
E.VacationHours AS "Vacation",
E.SickLeaveHours AS "Sick Time"
FROM HumanResources.Employee AS E;


1.8. Negating a Search Condition

SELECT Title,
FirstName,
LastName FROM Person.Person
WHERE NOT (Title = 'Ms.' OR Title = 'Mrs.');


1.9. Specifying a Range of Values

SELECT SalesOrderID,
ShipDate
FROM Sales.SalesOrderHeader
WHERE ShipDate BETWEEN '2005-07-23T00:00:00'
AND '2005-07-24T23:59:59';


1.10. Checking for NULL Values

SELECT ProductID,
Name,
Weight
FROM Production.Product
WHERE Weight IS NULL;


1.11. Providing a List of Values

SELECT ProductID,
Name,
Color
FROM Production.Product
WHERE Color IN ('Silver', 'Black', 'Red');


1.12. Performing Wildcard Searches

SELECT ProductID,
Name
FROM Production.Product
WHERE Name LIKE 'B%';

UPDATE Production.ProductDescription
SET Description = 'Chromoly steel. High % of defects'
WHERE ProductDescriptionID = 3;

SELECT ProductDescriptionID,
Description
FROM Production.ProductDescription
WHERE Description LIKE '%/%%' ESCAPE '/';


1.13. Sorting Your Results

SELECT p.Name,
h.EndDate,
h.ListPrice
FROM Production.Product AS p
INNER JOIN Production.ProductListPriceHistory AS h
ON p.ProductID = h.ProductID
ORDER BY p.Name,
h.EndDate;

1.14. Specifying Sort Order

SELECT p.Name,
h.EndDate,
h.ListPrice
FROM Production.Product AS p
INNER JOIN Production.ProductListPriceHistory AS h
ON p.ProductID = h.ProductID
ORDER BY p.Name DESC,
h.EndDate DESC;

1.15. Sorting by Columns Not Selected

SELECT p.Name
FROM Production.Product AS p
ORDER BY p.Color;


1.16. Forcing Unusual Sort Orers

SELECT p.ProductID,
p.Name,
p.Color
FROM Production.Product AS p
WHERE p.Color IS NOT NULL
ORDER BY CASE p.Color
WHEN 'Red' THEN NULL
ELSE p.Color
END;


1.17. Paging Through A Result Set

SELECT ProductID, Name
FROM Production.Product
ORDER BY Name
OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;

SELECT ProductID, Name
FROM Production.Product
ORDER BY Name
OFFSET 8 ROWS FETCH NEXT 10 ROWS ONLY;

0 comments on commit 5392963

Please sign in to comment.