Which code segment should you use?

CORRECT TEXT
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.

CORRECT TEXT
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.

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
)



Leave a Reply 5

Your email address will not be published. Required fields are marked *


To

To

–create an inline table-valued function named Sales.fn_OrdersByTerritory
CREATE FUNCTION Sales.fn_OrdersByTerritory (@T int)
–Accept the @T integer parameter
RETURNS TABLE
–an inline table-valued
AS
RETURN
(
SELECT OrderID,OrderDate,SalesTerrirotyID,TotalDue –Use one-part names to reference columns
–Return the columns in the same order as the order used in OrdersByTerritoryView
FROM Sales.OrdersByTerritory
WHERE SalesTerritoryID = @T
–Filter the query results by SalesTerritoryID
)

Lisa

Lisa

Create function named Sales.fn_OrdersByTerritory(@T int)

Return Table

AS
Return

(Select Orderid, Orderdate, SalesTerritoryId, TotalDue
from Sales.OrderbyTerritory
where SalesterritoryId = @T)

Patty

Patty

ALTER FUNCTION Sales.Fn_ordersbyterritory (@T INT)
RETURNS TABLE
AS
RETURN
(SELECT OrderID,
OrderDate,
SalesTerrytoryID,
TotalDue
FROM Sales.Orders
WHERE SalesTerrytoryID = @T)

Serge

Serge

You need to check first that it does note exist !!!

if Object_ID( N’Sales.Fn_ordersbyterritory’,N’IF’) IS NOT NULL
DROP Function Sales.Fn_ordersbyterritory;
GO
CREATE FUNC Sales.Fn_ordersbyterritory (

@ T int
)
Returns
TABLE
AS
Return (
SELECT OrderID, OrderDate, SalesTerrytoryID,TotlaDue,
FROM Sales.Orders,
WHERE SalesTerritoryID = @T;
)
GO