exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 77 discussion

Actual exam question from Microsoft's 70-761
Question #: 77
Topic #: 1
[All 70-761 Questions]

DRAG DROP -
Note: This question is part of a series of questions that use the same scenario. For your convenience, the scenario is repeated in each question. Each question presents a different goal and answer choices, but the text of the scenario is exactly the same in each question in this series.

Start of repeated scenario -
You have a database that contains the tables shown in the exhibit. (Click the Exhibit button.)

You review the Employee table and make the following observations:
✑ Every record has a value in the ManagerID except for the Chief Executive Officer (CEO).
✑ The FirstName and MiddleName columns contain null values for some records.
✑ The valid values for the Title column are Sales Representative manager, and CEO.
You review the SalesSummary table and make the following observations:
✑ The ProductCode column contains two parts: The first five digits represent a product code, and the last seven digits represent the unit price. The unit price uses the following pattern: ####.##.
✑ You observe that for many records, the unit price portion of the ProductCode column contains values.
✑ The RegionCode column contains NULL for some records.
✑ Sales data is only recorded for sales representatives.
You are developing a series of reports and procedures to support the business. Details for each report or procedure follow.
Sales Summary report: This report aggregates data by year and quarter. The report must resemble the following table.

Sales Manager report: This report lists each sales manager and the total sales amount for all employees that report to the sales manager.
Sales by Region report: This report lists the total sales amount by employee and by region. The report must include the following columns: EmployeeCode,
MiddleName, LastName, RegionCode, and SalesAmount. If MiddleName is NULL, FirstName must be displayed. If both FirstName and MiddleName have null values, the world Unknown must be displayed/ If RegionCode is NULL, the word Unknown must be displayed.
Report1: This report joins data from SalesSummary with the Employee table and other tables. You plan to create an object to support Report1. The object has the following requirements:
✑ be joinable with the SELECT statement that supplies data for the report
✑ can be used multiple times with the SELECT statement for the report
✑ be usable only with the SELECT statement for the report
not be saved as a permanent object

Report2: This report joins data from SalesSummary with the Employee table and other tables.
You plan to create an object to support Report1. The object has the following requirements:
✑ be joinable with the SELECT statement that supplies data for the report
✑ can be used multiple times for this report and other reports
✑ accept parameters
✑ be saved as a permanent object
Sales Hierarchy report: This report aggregates rows, creates subtotal rows, and super-aggregates rows over the SalesAmount column in a single result-set. The report uses SaleYear, SaleQuarter, and SaleMonth as a hierarchy. The result set must not contain a grand total or cross-tabulation aggregate rows.
Current Price Stored Procedure: This stored procedure must return the unit price for a product when a product code is supplied. The unit price must include a dollar sign at the beginning. In addition, the unit price must contain a comma every three digits to the left of the decimal point, and must display two digits to the left of the decimal point. The stored procedure must not throw errors, even if the product code contains invalid data.

End of Repeated Scenario -
You need to create the query for the Sales Managers report.
Which four Transact-SQL segments should you use to develop the solution? To answer, move the appropriate Transact-SQL segments from the list of Transact-
SQL segments to the answer area and arrange them in the correct order.
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:
From scenario: Sales Manager report: This report lists each sales manager and the total sales amount for all employees that report to the sales manager.
Box 1:..WHERE Title='Sales representative'
The valid values for the Title column are Sales Representative manager, and CEO.
First we define the CTE expression.
Note: A common table expression (CTE) can be thought of as a temporary result set that is defined within the execution scope of a single SELECT, INSERT,
UPDATE, DELETE, or CREATE VIEW statement. A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query.
Unlike a derived table, a CTE can be self-referencing and can be referenced multiple times in the same query.
Box 2:
Use the CTE expression one time.

Box 3: UNION -
Box 4:
Use the CTE expression a second time.
References:
https://technet.microsoft.com/en-us/library/ms190766(v=sql.105).aspx

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
AshleyLiang
Highly Voted 5 years, 10 months ago
My solution: WITH cte (ManagerID, EmployeeID, EmployeeCode, Title, SalesAmount) AS ( SELECT e.ManagerID, e.EmployeeID, e.EmployeeCode, e.Title, ss.SalesAmount FROM dbo.Employee e INNER JOIN dbo.SalesSummary ss ON e.EmployeeCode = ss.EmployeeCode WHERE ManagerID IS NULL UNION ALL SELECT e.ManagerID, e.EmployeeID, e.EmployeeCode, e.Title, cte.SalesAmount FROM dbo.Employee e INNER JOIN cte ON e.ManagerID = cte.EmployeeID ) SELECT ManagerID, EmployeeID, EmployeeCode, Title, SUM(SalesAmount) FROM cte GROUP BY ManagerID, EmployeeID, EmployeeCode, Title
upvoted 14 times
Bartek
5 years, 9 months ago
its wrong, returning SUM() as 0. see sample code CREATE TABLE #EMPLOYEES ( EMPLOYEEID INT, EMPLOYEECODE INT, FIRSTNAME VARCHAR(20),TITLE VARCHAR(140), MANAGERID INT) CREATE TABLE #SALESSUMMARY (EMPLOYEECODE INT, SALESAMOUNT DECIMAL(18,2)) INSERT INTO #EMPLOYEES VALUES (1,11,'BARTEK', 'SALES REPRESENTATIVE', 3), (2,13,'TOMEK','SALES REPRESENTATIVE',3), (3,12,'KASIA','SALES REPRESENTATIVE',4), (4,14,'WIKTOR','CTO',NULL) INSERT INTO #SALESSUMMARY VALUES (11,100),(12,200),(13,300),(14,0) ;WITH cte AS ( SELECT e.ManagerID, e.EmployeeID, e.EmployeeCode, e.Title, ss.SalesAmount FROM #EmployeeS e INNER JOIN #SalesSummary ss ON e.EmployeeCode = ss.EmployeeCode WHERE ManagerID IS NULL UNION ALL SELECT e.ManagerID, e.EmployeeID, e.EmployeeCode, e.Title, cte.SalesAmount FROM #EmployeeS e INNER JOIN cte ON e.ManagerID = cte.EmployeeID ) SELECT ManagerID, EmployeeID, EmployeeCode, Title, SUM(SalesAmount) FROM cte GROUP BY ManagerID, EmployeeID, EmployeeCode, Title
upvoted 2 times
...
M4x
5 years, 9 months ago
Agree (and tested). The solution use Where Title = 'Sales Representative' and specs says that field value can be: The valid values for the Title column are Sales Representative manager, and CEO.
upvoted 3 times
M4x
5 years, 9 months ago
Also missing the employees
upvoted 1 times
...
Braindripper
4 years, 9 months ago
M4x is correct because for managerID null - description above is: " Every record has a value in the ManagerID except for the Chief Executive Officer (CEO)." So first select wrongly will bring CEO sales.
upvoted 2 times
...
...
...
anonimdom
Highly Voted 5 years, 4 months ago
If we use "WHERE ManagerID IS NULL", the report will show not only sales managers but CEO too. Isn't it?
upvoted 7 times
ChargedNeutrons
4 years, 10 months ago
CEOs are managers.
upvoted 1 times
kimalto452
4 years, 6 months ago
The CEO takes final responsibility and ownership for the direction of the business, while a manager commonly only oversees a segment of the business and answers to a more senior person.
upvoted 1 times
...
...
...
Billybob0604
Most Recent 4 years, 5 months ago
AshleyLiang has got the correct solution. The anchor should have : where managerid is null
upvoted 1 times
...
Bartek
5 years, 9 months ago
Do not know that result (from hide bar) is fine becouse it produces duplicates throught UNION clause. In my opinion something like that : with cte as ( select e.managerid, e.employeeid, e.employeecode,e.title, ss.salesamount from #employees e join #salessummary ss on e.employeecode = ss.employeecode where title = 'sales representative' ) select managerid, employeeid,employeecode,title,sum(salesamount) as salesamount from cte group by managerid, employeeid, employeecode, title should be fine
upvoted 2 times
Bartek
5 years, 9 months ago
Complete solution : CREATE TABLE #EMPLOYEES ( EMPLOYEEID INT, EMPLOYEECODE INT, FIRSTNAME VARCHAR(20),TITLE VARCHAR(140), MANAGERID INT) CREATE TABLE #SALESSUMMARY (EMPLOYEECODE INT, SALESAMOUNT DECIMAL(18,2)) INSERT INTO #EMPLOYEES VALUES (1,11,'BARTEK', 'SALES REPRESENTATIVE', 3), (2,13,'TOMEK','SALES REPRESENTATIVE',3), (3,12,'KASIA','SALES REPRESENTATIVE',4), (4,14,'WIKTOR','CTO',NULL) INSERT INTO #SALESSUMMARY VALUES (11,100),(12,200),(13,300),(14,0) ;WITH cte AS ( SELECT e.ManagerID, e.EmployeeID, e.EmployeeCode, e.Title, ss.SalesAmount FROM #EmployeeS e INNER JOIN #SalesSummary ss ON e.EmployeeCode = ss.EmployeeCode where title = 'sales representative' UNION ALL SELECT e.ManagerID, e.EmployeeID, e.EmployeeCode, e.Title, cte.SalesAmount FROM #EmployeeS e INNER JOIN cte ON e.ManagerID = e.EmployeeID ) SELECT ManagerID, EmployeeID, EmployeeCode, Title, SUM(SalesAmount) FROM cte GROUP BY ManagerID, EmployeeID, EmployeeCode, Title
upvoted 4 times
Barbedx
5 years, 4 months ago
agree wth Bartek soluton, we need sales representative. but in INNER JOIN cte ON e.ManagerID = e.EmployeeID need change to cte.EmployeeeId
upvoted 3 times
Braindripper
4 years, 9 months ago
why not " ON cte.ManagerID = e.EmployeeID" ?? in the CTE will bring sales representatives and need to join their column managerID with table again to bring details about managers. correct?
upvoted 2 times
...
BabyBee
4 years, 7 months ago
It works! Bartek solution. but after UNION ALL join columns are: INNER JOIN cte ON cte.ManagerID = e.EmployeeID
upvoted 1 times
...
...
Aghie
4 years, 11 months ago
i agree that we need the 'Sales Representative' filter. tested both your solution and the solution from the 'Reveal Solution'. both shows same results.
upvoted 1 times
Aghie
4 years, 10 months ago
agree on Bartek's solution. missed that the given solution is only using 'union'
upvoted 1 times
Aghie
4 years, 9 months ago
also, "total sales amount for all employees that report to the sales manager" so it means the employees need to have managerID
upvoted 1 times
...
...
...
ChargedNeutrons
4 years, 10 months ago
It's a recursive CTE. See this link https://www.sqlservertutorial.net/sql-server-basics/sql-server-recursive-cte/
upvoted 1 times
...
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...