Question

--* BUSIT 103                   Assignment   #3                       DUE DATE...

--* BUSIT 103                   Assignment   #3                       DUE DATE : Consult course calendar
                          
/* You are to develop SQL statements for each task listed. You should type your SQL statements
   under each task. You should always create an alias for any derived fields. Add a sort that makes
   sense for each query. */

USE AdventureWorksLT2012;

--1.   Build a single column of data in which you concatenate the text ...
--
--           Welcome back,
--      
--       .. to the FirstName and LastName field for each customer, and then to an exclamation point.
--       The first record should display as follows:
--
--           Welcome back, Catherine Abel!
--
--       Give the column the alias WelcomeDisplay.
--       Order the results in alphabetical order by last name then by first name.

--2.   Using concatenation, build a single column of data that displays as follows:
--
--           Catherine Abel your ID is 29485.
--      
--       Note that in the sample display Catherine Abel and 29485 come from fields.
--       And note that " your ID is " and the period at the end of the phrase are static text.
--
--       Give the column the alias CustomerDisplay.
--       Order the results in alphabetical order by last name then by first name.


--3.   Using concatenation, build a single column of data that displays product category numbers
--       and names in one column as follows:
--  
--                   Product Category 1: Bikes
--
--       Note that "Product Category" and the colon ":" are static text.
--       Note that number and name, in this case the 1 the name Bikes, are field values.
--       Give the column a meaningful alias and sort order.


  
--4.   Run and view the following code:

       select
           SalesOrderID
           , UnitPrice * (1-UnitPriceDiscount) * OrderQty
           , LineTotal
       from [SalesLT].[SalesOrderDetail];

--       Copy and paste the above code into a. and b. below where you will use CAST() and CONVERT() on
--       Columns 2 and 3 to display numeric values to exactly 2 decimal places. Column 2 and 3 should
--       show the same amount. LineTotal (Column 3) is included to double check your calculation;
--       the two amounts should match. Add a meaningful sort to the statement.


--a.   CAST is the ANSI standard. Write the statement using CAST with decimal as the data type.

--b.   Write the statement again using CONVERT with decimal as the data type. CONVERT is a T-SQL function.
--       

--5.   AdventureWorks predicts a 6% increase in production costs for all their products.
--       They wish to see how the increase will affect their profit margins. To help them
--       understand the impact of this increase in production costs (StandardCost), you will create
--       a list of all products showing ProductID, Name, ListPrice, FutureCost (use StandardCost * 1.06
--       to compute FutureCost), and Profit (use ListPrice minus the calculation for FutureCost to find Profit).
--
--       All money values are to show exactly 2 decimal places. Order the results descending by Profit.
--       FYI: Read online about the "Logical Query Processing Phases". It will explain why you
--       cannot use an alias created in the SELECT clause in a calculation but can use it in the ORDER BY clause.

--   a.   First write the requested statement using CAST. CAST is the ANSI standard. There will be five
--       fields (columns). There will be one row for each product in the Product table.

--b.   Next write the statement from 5a again using CONVERT. There will be five
--       fields (columns). There will be one row for each product in the Product table.

--6.   For a. and b. below, list all sales orders showing PurchaseOrderNumber, SalesOrderID, CustomerID, OrderDate,
--       DueDate, and ShipDate. Format the datetime fields so that no time is displayed. Be sure to give each derived
--       column an alias and add a meaningful sort to each statement.

--a.   CAST is the ANSI standard. Write the statement using CAST.

--b.   Write the statement again using CONVERT.

--c.   Write a statement using either 6a or 6b add a field that calculates the
--       difference between the due date and the ship date. Name the field ShipDays and show
--       the result as a positive number. Be sure Datetime fields still show only the date.
--       The DateDiff function is not an ANSI standard; don't use it in this statement.

--d.   Rewrite the statement from 6c to use the DateDiff function to find the
--       difference between the OrderDate and the ShipDate. Again, show only the date in datetime fields.



--7.   EXPLORE: Research the following on the Web for an answer:
--       Find a date function that will return a datetime value that contains the date and time from the computer
--       on which the instance of SQL Server is running (this means it shows the date and time of the PC on which
--       the function is executed). The time zone offset is not included. Write the statement so it will execute.
--       Format the result to show only the date portion of the field and give it the alias of MyPCDate.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Since you have not provided the db schema, I am providing the queries by guessing the table and column names. Feel free to reach out in case of any concerns.

1)

SELECT ('Welcome back, ' || firstName || ' ' || lastName || '!') as WelcomeDisplay from Customer ORDER BY lastName, firstName;

2)

SELECT (firstName || ' ' || lastName || ' your ID is ' || customerID || '.') as CustomerDisplay from Customer ORDER BY lastName, firstName;

NOTE: As per Chegg policy I am allowed to answer specific number of questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.

Add a comment
Know the answer?
Add Answer to:
--* BUSIT 103                   Assignment   #3                       DUE DATE...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5. Write a SELECT statement that returns these columns from the Orders table: OrderID OrderDate ShipDate...

    5. Write a SELECT statement that returns these columns from the Orders table: OrderID OrderDate ShipDate Return only the rows where the ShipDate column contains a null value. 6. Write a SELECT statement that returns all columns from the Addresses table State is equal to CA 7. Write a SELECT statement that returns all columns from the Products table Product name has a "ru" in its name 8. Write a SELECT statement that returns these columns from the Customers table...

  • QUESTIONS Q01: Use the comment feature of SQL to print your full name, AUID and username in three separate lines at the top of the script file. From this point onwards, you should use the comment fea...

    QUESTIONS Q01: Use the comment feature of SQL to print your full name, AUID and username in three separate lines at the top of the script file. From this point onwards, you should use the comment feature to separate your answers for each question. (0.2 mark) Q02: Write a SQL statement to retrieve all the rows from the Product table. All the columns should be renamed with proper spacing using the alias feature. For example, the UnitPrice column should be...

  • pls help me with these SQL questions Here are tables TEAM table Task 10 (4 marks)...

    pls help me with these SQL questions Here are tables TEAM table Task 10 (4 marks) Write an SQL statement to display fan categories, the number of tickets in each category the fan bought (change the alias to "NUMBER OF TICKETS PURCHASED") along with the sum of prices (change the alias to TOTAL PRICES') in each category the fans paid. Sort the result by total price in an ascending order. Task 11 (5 marks) Write an SQL statement to display...

  • I need to write an SQL statement to run this query: SALES has the following column...

    I need to write an SQL statement to run this query: SALES has the following column names: vendorid, name, upc, move, price, qty, year, store the table name is SALES... the sales is not a column in the SALES so it needs to be created in the query with the formula as well. QUESTION BELOW: Query 4: Return the vendor id, vendor name, product UPC code, move, and sales (price * move/qty) for each product sold by store 100 in...

  • Hi good day i need homework help fast please d32 1./What is the maximum length that...

    Hi good day i need homework help fast please d32 1./What is the maximum length that a VARCHAR data type can be: a. 65535 b. 1023 C. 255 d. 32767 2.) Why are alias' used for table and columns? a. to make the names easier to understand b. to hide the column or table c. to be able to remove them from the database d. to give the appearance that they are new- 3.)What does the FIELD function allow you...

  • CUSTTYPE (TID, TypeDesc) CUSTOMER (CID, Lname, Fname, TID, Address, ZIPcode) CUSTORDER (OrderNo, OrderDate, PromiseDate, ShippedDate, ShippingTerm,...

    CUSTTYPE (TID, TypeDesc) CUSTOMER (CID, Lname, Fname, TID, Address, ZIPcode) CUSTORDER (OrderNo, OrderDate, PromiseDate, ShippedDate, ShippingTerm, SalesID, CID) SALESREP (SalesID, Name, Phone, Address, ZIPcode, RepType) ORDERLINE (OrderNo, PID, Qty, Qty_RETD) FTSALESREP (SalesID, MonthPay, Rank) PTSALESREP (SalesID, HourlyRate, WeekHours) ZIP_TABLE (ZIPcode, City, State) VENDOR (VID, Name, Phone ZIPcode) PRODUCT (PID, CateID, ProdName, ProdFinish, Price, Qty_on_Hand, Description, VID) CATEGORY (CateID, CateType) Local View #1: Use three base tables to develop a SQL statement that will list the following information for a customer,...

  • Note: Use the City Jail database created with the CityJail_8.sql script that you ran for the...

    Note: Use the City Jail database created with the CityJail_8.sql script that you ran for the Chapter 8 case study. The following list reflects the current data requests from city managers. Provide the SQL statements that satisfy the requests. For each request, include one solution using the traditional method and one using an ANSI JOIN statement. Test the statements and show execution results 4. Create an alphabetical list of all criminals, including criminal ID, name, violent offender status, parole status,...

  • Prepare and execute each of the queries listed using the "Adventureworks2012" database in SQL: Server: http://msftdbprodsamples.codeplex.com/releases/view/93587...

    Prepare and execute each of the queries listed using the "Adventureworks2012" database in SQL: Server: http://msftdbprodsamples.codeplex.com/releases/view/93587 When all of your queries are complete, cut and paste the SQL Syntax into a word document. In order to see what the column names are, you need to click on the table and then Columns to see the field names. Make sure to include column headings that make sense in the queries (use the as “Field Name” after the field selected). Multi-table Queries...

  • Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accoun...

    Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accounting, and employee data, and these different data sets must all be efficiently managed in order to make the data accessible. Companies rely on database engineers to ensure that their records are accurate, updated, and tracked in real time. This course covers structured query language (SQL) and how it can be used to manage database schemas, manipulate data, and analyze data. For your final...

  • Chapter 2 How to use the Management Studio Before you start the exercises... Before you start...

    Chapter 2 How to use the Management Studio Before you start the exercises... Before you start these exercises, you need to install SQL Server and the SQL Server Management Studio. The procedures for doing both of these tasks are provided in appendix A of the book. In addition, you'll need to get the Exercise Starts directory from your instructor. This directory contains some script files that you need to do these exercises. Exercises In these exercises, you'll use SQL Server...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT