DRAG DROP
You use Microsoft SQL Server 2012 to develop a database application.
You create two tables by using the following table definitions.
Which six Transact-SQL statements should you use? (To answer, move the appropriate SQL
statements from the list of statements to the answer area and arrange them in the correct order.)
Explanation:
Seems to be correct
https://msdn.microsoft.com/en-us/library/ms175156.aspx
1-2-6-3-5
The question is Wrong, it says: “Which six Transact-SQL statements should you use?”
But the 1-2-6-3-5 is the right answer
CREATE FUNCTION dbo.getsubtree(@empid AS int)
RETURNS @Tree TABLE(
empid int NOT NULL,
empname varchar(25) NOT NULL,
mgrid int NULL,
lvl int NOT null
)
AS BEGIN
WITH Employees_Subtree(empid, empname, mgrid, lvl)
AS
(
SELECT empid, empname, mgrid, 0
FROM Employees WHERE empid=@empid
UNION ALL
SELECT e.empid, e.empname, e.mgrid, es.lvl+1
FROM employees AS e
JOIN Employees_SubTree AS es
ON e.mgrid=es.empid
)
INSERT INTO @Tree
SELECT * form Employees_Subtree;
RETURN
END
Thanks …