exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 12 discussion

Actual exam question from Microsoft's 70-761
Question #: 12
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.
You query a database that includes two tables: Project and Task. The Project table includes the following columns:


Task level is defined using the following rules:

You need to determine the task level for each task in the hierarchy.
Which five 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:
Box 1: SELECT CAST (NULL AS INT) AS ParentTaskID, etc.
This statement selects all tasks with task level 0.
The ParentTaskID could be null so we should use CAST (NULL AS INT) AS ParentTaskID.

Box 2: UNION -
We should use UNION and not UNION ALL as we do not went duplicate rows.
UNION specifies that multiple result sets are to be combined and returned as a single result set.
Incorrect Answers:
Not UNION ALL: ALL incorporates all rows into the results. This includes duplicates. If not specified, duplicate rows are removed.
Box 3, Box 4, Box 5:
These statements select all tasks with task level >0.
References:
https://msdn.microsoft.com/en-us/library/ms180026.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
Tazul
Highly Voted 5 years, 10 months ago
Correct Answer: With TaskWithTaskLevel (ParentTaskID,TaskID,TaskName,TaskLevel) As ( Select Cast(null as int) ParentTaskID, T.TaskID,T.TaskName,0 as TaskLevel From Task T where ParentTaskID is null Union All Select R.TaskID as ParentTaskID, T.TaskID,T.TaskName,R.TaskLevel + 1 as TaskLevel From Task T Inner join TaskWithTaskLevel R on T.ParentTaskID = R.TaskID ) Select * from TaskWithTaskLevel
upvoted 45 times
mlourinho
5 years, 7 months ago
I agree, but it can be just UNION
upvoted 2 times
mlourinho
5 years, 6 months ago
I was wrong. It has to be UNION ALL. Recursive CTE will only work with UNION ALL.
upvoted 13 times
...
...
...
Hoey
Highly Voted 5 years, 2 months ago
union cannot be used in WIth recursive.
upvoted 6 times
...
Anirudh_net
Most Recent 3 years, 3 months ago
It can be just UNION
upvoted 1 times
...
DonPatrick
4 years, 4 months ago
3 2 7 5 1
upvoted 1 times
...
TheDUdeu
4 years, 9 months ago
UNION ALLL Drop TABLE IF EXISTS #Task Drop TABLE IF EXISTS #Project CREATE Table #Project ( ProjectId UNIQUEIDENTIFIER NOT NULL, ProjectName varchar(100), StartTime dateTime2(7), EndTime dateTime2(7), UserId Int ) CREATE Table #Task ( TaskId UNIQUEIDENTIFIER NOT NULL, TaskName varchar(100), ParentTaskId int, ProjectId int, StartTime dateTime2(7), EndTime dateTime2(7), UserId Int ) With TaskWithTaskLevel (ParentTaskID,TaskID,TaskName,TaskLevel) As ( Select Cast(null as int) ParentTaskID, T.TaskID,T.TaskName,0 as TaskLevel From Task T where ParentTaskID is null Union ALL Select R.TaskID as ParentTaskID, T.TaskID,T.TaskName,R.TaskLevel + 1 as TaskLevel From Task T Inner join TaskWithTaskLevel R on T.ParentTaskID = R.TaskID ) Select * from TaskWithTaskLevel
upvoted 4 times
ASQL
4 years, 7 months ago
agreed that is the correct solution
upvoted 1 times
Vermonster
4 years, 5 months ago
Agreed - need UNION ALL to make recursion work. 0 is top level, +1 on bottom
upvoted 1 times
...
...
...
stm22
4 years, 11 months ago
Select Cast(null as int) returns a null, not a zero
upvoted 2 times
...
M4x
5 years, 9 months ago
UNION OR UNION ALL, I think UNION for filter duplicates
upvoted 3 times
lh2607
4 years, 5 months ago
Union cannot be used with Recursive CTEs. Only Union All can.
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 ...