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.
Sales.fn_OrdersByTerritory must meet the following requirements:
Use one-part names to reference columns.
Return the columns in the same order as the order used in OrdersByTerritoryView.
Part of the correct T-SQL statement has been provided in the answer area. Provide the complete
code.
Answer: See the explanation
Explanation:
CREATE FUNCTION Sales.fn_OrdersByTerritory (@T int)
RETURNS TABLE
AS
RETURN
(
SELECT
OrderID,
OrderDate,
SalesTerritoryID,
TotalDue
FROM Sales.OrdersByTerritory
WHERE SalesTerritoryID=@T
)
CREATE FUNCTION Sales.fn_OrdersByTerritory
RETURN TABLE
AS
RETURN
(SELECT
ORDERID,
ORDERDATE,
SALESTerritoryID,
TotalDue
FROM Sales.Orders
)
Actually, you need empty parenthesis at the end of the create function even if there is no variable being passed. And, the first RETURN is RETURNS…
CREATE FUNCTION Sales.fn_OrdersByTerritory()
RETURNS TABLE
That is the only I’ve found to make the query actually work…
CREATE FUNCTION Sales.fn_OrdersByTerritory
RETURNS TABLE
AS
RETURN
(SELECT
ORDERID,
ORDERDATE,
SALESTerritoryID,
TotalDue
FROM Sales.Orders
)