Chapter 9 Lab - working with data types and functions(1)

docx

School

Greenville Technical College *

*We aren’t endorsed by this school

Course

272

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

7

Uploaded by HighnessFlowerBadger33

Report
Chapter 9 Lab – Working with data types and functions Name: __Lesly Mendoza______________ Date: 10/18/23___________________ Exercise Instructions 1. Type your name and the date into the space provided. 2. Use the SQL Server Management Studio to complete this lab. 3. Complete each of the exercises in this lab per the directions provided below. 4. Upload and submit before the due date. Exercises 1. Write a select that produces a list that shows the 4-digit year of each year when Eagle's Assembly employees were born and the number of Assembly employees born in that year. Hints: a. Any employee with a job title of Assembly is an Assembly employee. Use a WHERE clause to limit the rows you select. b. You probably want to use the Year, and count functions when solving this exercise. c. You will need to use a GROUP BY since the count function is an aggregate function. Paste below the code you wrote and the run results you obtained for this exercise: SELECT YEAR ( BirthDate ) AS Year , COUNT (*) AS NumberOfEmployeesBorn FROM Employee WHERE JobTitle = 'Assembly' GROUP BY YEAR ( BirthDate )
Chapter 9 Lab – Working with data types and functions Name: __Lesly Mendoza______________ Date: 10/18/23___________________ ------------------------------------------ 2. Write a select that produces a list that shows each month and the number of Eagle Engineer employees born each month. Format your results like the example shown. Hints: a. The database is subject to insertions and deletions so your run results may differ from the sample. b. An engineer is an employee with a job title that contains the word engineer. Month EngineersBorn ------------------------------ ------------- June 2 May 1 November 1 September 1 (4 rows affected) Paste below the code you wrote and the run results you obtained for this exercise: SELECT DATENAME ( month , BirthDate ) AS Month , COUNT (*) AS EngineersBorn FROM Employee WHERE JobTitle = 'Engineer' GROUP BY DATENAME ( month , BirthDate )
Chapter 9 Lab – Working with data types and functions Name: __Lesly Mendoza______________ Date: 10/18/23___________________ ------------------------------------------ 3. Write a select that list each engineer’s name, and how many years the engineer has worked for the Eagle Corporation. Paste below the code you wrote and the run results you obtained for this exercise: SELECT CONCAT ( FirstName , ' ' , LastName ) AS EngineerName , DATEDIFF ( year , HireDate , GETDATE ()) AS YearsWithCompany FROM Employee WHERE JobTitle = 'Engineer'
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Chapter 9 Lab – Working with data types and functions Name: __Lesly Mendoza______________ Date: 10/18/23___________________ ----------------------------------------------------------------------- 4. Write a select that list each Assembly employee’s name, job title, and age (in years). Paste below the code you wrote and the run results you obtained for this exercise: SELECT CONCAT ( FirstName , ' ' , LastName ) AS EmployeeName , JobTitle , DATEDIFF ( year , BirthDate , GETDATE () ) AS AgeInYears FROM Employee WHERE JobTitle = 'Assembly' Joanne Rosner Assembly 48 Michelle Nairn Assembly 36 David Keck Assembly 52 Ronald Butler Assembly 50 Steve Hess Assembly 49 Allison Roland Assembly 45 Joseph Platt Assembly 42 Nicholas Albregts Assembly 41 Kathryn Deagen Assembly 50 Kristey Moore Assembly 41 Austin Ortman Assembly 42 Patricha Underwood Assembly 43 Melissa Alvarez Assembly 32 Jack Brose Assembly 48 David Deppe Assembly 39 Gregory Hettinger Assembly 49 Phil Reece Assembly 45 John Boden Assembly 31
Chapter 9 Lab – Working with data types and functions Name: __Lesly Mendoza______________ Date: 10/18/23___________________ ------------------------------------------ 5. Write a select to list names of eagle’s customers (use the Customer Table). If the company name is not null list it, if the company name is null list the customer name (first name and last name). Your results should come back looking similar to the following (the database is subject to insertions and deletions so these partial results are shown only to convey the nature of the results not necessarily specific records). Customer_Name ---------------------------------------- Baker and Company Cole Sales and Associates Tippe Inn Franklin Trinkets . . . Linda Li (231 row(s) affected) Hint: use ISNULL or COALESCE function in your SELECT list to control what is displayed. Paste below the code you wrote and type the number of rows returned for this exercise: SELECT ISNULL ( CompanyName , CONCAT ( CustFirstName , ' ' , CustLastName )) AS CustomerName FROM Customer 237 Rows ------------------------------------------ 6. Write a select that produces a list that shows the company name of each company that ordered something from the eagle company during a month of October (year does not matter). Do not include rows for companies with a CompanyName that begins with the letter ‘F’. Also, do not include rows for companies that have a null value for Company Name. Sort the list by CompanyName in descending sequence. Paste below the code you wrote and the run results you obtained for this exercise:
Chapter 9 Lab – Working with data types and functions Name: __Lesly Mendoza______________ Date: 10/18/23___________________ SELECT C . CompanyName , CONCAT ( DATENAME ( month , CO . OrderDate ), ' ' , DAY ( CO . OrderDate ), ',' , YEAR ( CO . OrderDate )) AS OrderDate FROM Customer C , CustOrder CO WHERE C . CustomerID = CO . CustomerID AND MONTH ( CO . OrderDate ) = 10 AND C . CompanyName IS NOT NULL AND C . CompanyName NOT LIKE 'F%' ORDER BY C . CompanyName DESC ------------------------------------------ 7. Write a select that produces a list that shows the Customer FirstName, LastName, and Phone of each of eagles non-corporate customers that has ordered something during a month of October (year does not matter).Hint: A non-corporate customer has a null value for company name. Paste below the code you wrote and type the number of rows returned for this exercise: SELECT C . CustFirstName , C . CustLastName , C . Phone FROM Customer C , CustOrder CO WHERE C . CustomerID = CO . CustomerID AND MONTH ( CO . OrderDate ) = 10
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Chapter 9 Lab – Working with data types and functions Name: __Lesly Mendoza______________ Date: 10/18/23___________________ AND C . CompanyName IS NULL 39 Rows ------------------------------------------ 8. Write a select that produces a list that shows the company name of each company that ordered something from the eagle company during a spring. Year does not matter (it does not matter what spring). Do not include rows for companies with a CompanyName that begins with the letter ‘F’. Also, do not include rows for companies with a null value for CompanyName. Sort the list by CompanyName. Consider a date to be in the spring if its dayofyear value is between 79 and 170 (inclusive between) */ Paste below the code you wrote and type the number of rows returned for this exercise: SELECT C . CompanyName , CO . OrderDate FROM Customer C , CustOrder CO WHERE C . CustomerID = CO . CustomerID AND C . CompanyName IS NOT NULL AND C . CompanyName NOT LIKE 'F%' AND DATEPART ( DAYOFYEAR , CO . OrderDate ) > = 79 AND DATEPART ( DAYOFYEAR , CO . OrderDate ) < = 170 ORDER BY C . CompanyName 16 Rows ------------------------------------------------------------