Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Topic 6 Query included at the bottom. Please assist as much as possible. Details

ID: 3885622 • Letter: T

Question

Topic 6 Query included at the bottom.

Please assist as much as possible.

Details:

The purpose of this assignment is to update a previous query and present it in an easily readable format.

For this assignment, continue to assume the role of a data analyst at Adventure Works Cycles Company.

Part 1

Using what you have learned, replicate the data found in #MySalesOrderDetailbyDate and #MyProductPriceHistory using a single line of SQL code. Using the query completed in the Topic 6 assignment, modify the query and present it in an easy-to-read format. To do this, write the query in two single statements without temporary tables, using abbreviations and line spacing.

Please note that when SQL queries are run, results are generated in the form of data. This data should be exported and saved to Excel for a visual check of accuracy.

Create a Word document that includes the SQL query code.

Part 2

Karen Berge, a Document Control Assistant at the company, comes to you with a request. Karen wants the titles and file names of all of the documents she has produced and has asked you to generate this information for her. Using what you have learned, produce a query in one statement to give her the information she needs. Note that constructing the query will require some thinking outside the box since the relationships are not well documented.

Please note that when SQL queries are run, results are generated in the form of data. This data should be exported and saved to Excel for a visual check of accuracy. This Excel file should include the names of all documents Karen has produced.

Add to the Word document you created in Part 1 and include the SQL query code associated with the query you wrote to locate Karen's documents.

Select *

From MyProduct;

Select*

From MyPriceHistory;

Select MP.ProductID, MP.Name, MP.ListPrice, MPH.EndDate

Into #MyProductPriceHistory

From MyProduct As MP

Inner Join MyPriceHistory AS MPH

On MP.ListPrice=MPH.ListPrice;

Select*From #MyProductPriceHistory

Where EndDate IS NOT NULL;

Question 2

Select*

From MyProduct

Select*

From [Sales].[SalesOrderDetail];

Select MP.ProductID, MP.Name, SO.SalesOrdeID, SO.OrderQty

Into #MySalesHistory

From MyProduct AS MP

Inner JOin [Sales].[SalesOrderDetail] AS So

ON MP.ProductID = SO.ProductID;

Select*

From #MySalesHistory

Question 3

Select SOD.ProductID, SOH.OrderDate

Into #MyTemp

From AS SOD

Inner Join [Sales].[SalesOrderHeader] AS SOH

ON SOD.SalesOrderID=SOH.SalesOrderID;

Select MP.Name, SOD.OrderQty, MP.ProductID

INTO #MySalesHistory

From MyProduct AS MP

Inner Joins [Sales].[SalesOrderDetail] AS SOD

ON MP.ProductID=SOD.ProductID;

Select MT.ProductID, MT.OrderDate, MSH.Name, MSH.OrderQty

From #MyTemp as MT

Inner JOin #MySalesHistory AS MSH

On MT.ProductID=MSH.ProductID

Order BY OrderDate ASC;

Select Sum(OrderQty) AS "Quantity Sum"

From #MySalesHistory

Explanation / Answer

1)

To only select the data from table:

Select

MP.ProductID,

MP.Name,

MP.ListPrice,

MPH.EndDate

From MyProduct As MP

Inner Join MyPriceHistory AS MPH

On MP.ListPrice=MPH.ListPrice

Where

MPH.EndDate IS NOT NULL

In case, you directly want to export results to excel:

INSERT INTO OPENROWSET

('Microsoft.Jet.OLEDB.4.0',

'Excel 8.0;Database=c:Test.xls;',

Select

MP.ProductID,

MP.Name,

MP.ListPrice,

MPH.EndDate

From MyProduct As MP

Inner Join MyPriceHistory AS MPH

On MP.ListPrice=MPH.ListPrice

Where

MPH.EndDate IS NOT NULL

2)

To only select the data from table:

Select

MP.ProductID,

MP.Name,

SO.SalesOrdeID,

SO.OrderQty

From MyProduct AS MP

Inner JOin [Sales].[SalesOrderDetail] AS So

ON MP.ProductID = SO.ProductID;

In case, you directly want to export results to excel:

INSERT INTO OPENROWSET

('Microsoft.Jet.OLEDB.4.0',

'Excel 8.0;Database=c:Test.xls;',

Select

MP.ProductID,

MP.Name,

SO.SalesOrdeID,

SO.OrderQty

From MyProduct AS MP

Inner JOin [Sales].[SalesOrderDetail] AS So

ON MP.ProductID = SO.ProductID

');

3)

There are 4 sql statements. First 2 are creating temp tables and other 2 are selecting data. I am going to present single select statements representation for the 2 select statements (as expected). To export them into excel, either you can write the export the data using above format i mentioned or you can copy-paste them (in case data size is not too large).

First select statement:

SELECT

MP.ProductID,

SOH.OrderDate,

MP.Name,

SOD.OrderQty

FROM MyProduct AS MP

INNER JOIN [Sales].[SalesOrderDetail] AS SOD

ON MP.ProductID=SOD.ProductID

INNER JOIN [Sales].[SalesOrderHeader] AS SOH

ON SOD.SalesOrderID=SOH.SalesOrderID

Order BY OrderDate ASC;

Second select statement:

SELECT

Sum(SOD.OrderQty) AS "Quantity Sum"

FROM MyProduct AS MP

INNER JOIN [Sales].[SalesOrderDetail] AS SOD

ON MP.ProductID=SOD.ProductID

INNER JOIN [Sales].[SalesOrderHeader] AS SOH

ON SOD.SalesOrderID=SOH.SalesOrderID;

The keven part data in not given :(. The query informaiton is not given only description is given.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote