You are on page 1of 3

Chapter 3 Query Lab

Name: Jonathan Kilgore

Date: 8/28/2014
Exercise Instructions

1. Type your name and the date in the spaces provided.


2. Use the SQL Server Management Studio.
3. Write T-SQL statements to query the tables contained in the IST272EagleCorp
database.
4. Paste your solutions to exercises 1 through 10 into the indicated areas below:

Exercises
1. Write a SELECT statement that returns four columns from
the Shipper table:
ShipperID, ShipperName, ContactName, Phone
Paste exercise 1 answer here:
Select ShipperID, ShipperName, ContactName, Phone
From Shipper

-----------------------------------------------2. Write a SELECT statement that returns six columns from


the PurchOrderLine table named OrderID, Supplier, CNumber,
UQ, OUC, and EC:
OrderID Column alias for the PurchOrderID
Supplier Column alias for the SupplierID
CNumber Column alias for the CatalogNumber
UQ Column alias for the UnitQuantity
OUC Column alias for the OrderedUnitCost
EC UnitQuanity times the OrderedUnitCost
Hint:

Use the AS keyword to assign column aliases.

Paste exercise 2 answer here:


Select PurchOrderID AS OrderID,
SupplierID AS Supplier,
CatalogNumber AS CNumber,
UnitQuantity AS UQ,
OrderedUnitCost AS QUC,
UnitQuantity * OrderedUnitCost AS EC
From PurchOrderLine

------------------------------------------------

Chapter 3 Query Lab


3. Write a SELECT statement that returns one column from the Employee
table named Full_Name. Create this column from the LastName and
FirstName columns. Format it as follows: last name, comma, first name
(for example "Doe,John"). Sort the result set by last name, then by
first name.
Paste exercise 3 answer here:
Select LastName + ', ' + FirstName AS [Full Name]
From Employee
ORDER BY LastName, FirstName;

-----------------------------------------------4. Write a SELECT statement that returns six columns from the
InventoryPart table: named PartNumber, PartDescription, EOQ,
ReorderLevel, StockLevel, StockOnOrder
Only return those rows where a reorder needs to be placed
(Stocklevel is less than the ReorderLevel minus the StockOnOrder)
Sort the results by StockLevel with the smallest StockLevel first.
Paste exercise 4 answer here:
Select PartNumber, PartDescription, EOQ, ReorderLevel, StockLevel, StockOnOrder
From InventoryPart
Where Stocklevel < Reorderlevel - StockOnOrder
Order By StockLevel DESC

-----------------------------------------------5. Modify the solution to exercise 2 to filter for rows with a


UnitQuantity value that's greater than or equal to 10 but less than or
equal to 15.
Paste exercise 5 answer here:
Select PurchOrderID AS OrderID,
SupplierID AS Supplier,
CatalogNumber AS CNumber,
UnitQuantity AS UQ,
OrderedUnitCost AS QUC,
UnitQuantity * OrderedUnitCost AS EC
From PurchOrderLine
Where UnitQuantity >=10 AND UnitQuantity <=15

-----------------------------------------------6. Modify the solution to exercise 3 to filter for Employees


whose lastname begins with the letter B, C, or R.
Paste exercise 6 answer here:
Select LastName + ', ' + FirstName AS [Full Name]
From Employee
Where LastName LIKE '[B-C, R]%'
ORDER BY LastName, FirstName;

------------------------------------------------

Chapter 3 Query Lab


7. Modify the solution to exercise 3 to filter for Employees
whose lastname begins with the two letters Bu (for example a last name
of name Bush should get selected, and a last name of Blume should not
get selected")
Paste exercise 7 answer here:
Select LastName + ', ' + FirstName AS [Full Name]
From Employee
Where LastName LIKE 'Bu%'
ORDER BY LastName, FirstName;

-----------------------------------------------8. Modify the solution to exercise 3 to filter for Employees


whose lastname begins with the letter O and ends with the letter N.
Paste exercise 8 answer here:
Select LastName + ', ' + FirstName AS [Full Name]
From Employee
Where LastName LIKE 'O%N'
ORDER BY LastName, FirstName;

-----------------------------------------------9. Write a SELECT statement that returns six columns from


the Customer table named CustomerID, CompanyName, CustLastName,
State, Phone, Fax. Filter for Customers that have a non-null value
for their companyName.
Paste exercise 9 answer here:
Select CustomerID, CompanyName, CustLastName, [State], Phone, Fax
From Customer
Where CompanyName Is Not Null

-----------------------------------------------10. Write a SELECT statement that returns four columns from


the Customer table named CustomerID, CustLastName,
State, Phone. Filter for Customers that have a null value
for their companyName.
Paste exercise 10 answer here:
Select CustomerID, CustLastName,[State], Phone
From Customer
Where CompanyName is Null

------------------------------------------------

You might also like