PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You have a view that was created by using the following code:

You need to create an inline table-valued function named Sales.fn_OrdersByTerritory, which
must meet the following requirements:
• Accept the @T integer parameter.
• Use one-part names to reference columns.
• Filter the query results by SalesTerritoryID.
• Return the columns in the same order as the order used in OrdersByTerritoryView.
Which code segment should you use?
To answer, type the correct code in the answer area.

PrepAway - Latest Free Exam Questions & Answers

Answer: See the explanation.

Explanation:
CREATE FUNCTION Sales.fn_OrdersByTerritory (@T int)
RETURNS TABLE
AS

RETURN
(
SELECT OrderID,OrderDate,SalesTerrirotyID,TotalDue
FROM Sales.OrdersByTerritory
WHERE SalesTerritoryID = @T
)

5 Comments on “Which code segment should you use?

  1. saurabh sarkar says:

    create function Sales.fn_OrdersByTerritory(@t int)
    returns table
    as
    return
    (
    select orderid,orderdate,salesTerritoryId,TotalDue
    from Sales.OrderbyTerritory
    where SalesTerritoryId = @t
    );




    2



    0
  2. Scotty says:

    Saurabh, there is an error in the FROM part of your query.

    See below for full correct query

    CREATE FUNCTION Sales.ufn_OrdersByTerritory (@t INT)
    RETURNS TABLE
    AS
    RETURN
    (
    SELECT OrderID, OrderDate, SalesTerritoryID, TotalDue
    FROM Sales.Orders
    WHERE SalesTerritoryID = @t
    );
    GO




    2



    0
  3. Filipe Araujo says:

    The only think that is wrong in the first answer is “Sales.OrderbyTerritory” cause this object does not exists. So, the correct is “Sales.OrdersbyTerritory” (using the view name) in the FROM clause.
    The second answer looks well, cause it is using the table name on clause FROM.




    0



    1

Leave a Reply