Microsoft Exam Questions

How would you create this inline table-valued function?

CORRECT TEXT
You are employed as a SQL Server 2012 database developer at ABC.com. ABC.com has a
SalesDB database with a view named SalesV. The SalesV view was created using the following
Transact-SQL code:
CREATE VIEW SalesDB.ProductsSalesV
AS
SELECT OrderID, ProductID, ShipDate, OrderDate, Amount
FROM SalesDB.Orders;
You want to create an inline table-valued function named fn_ABC that accepts a @ProductID
parameter of the integer data type. The inline table-valued function should also allow for sales
orders for each product to be listed by the latest sale.
How would you create this inline table-valued function?
To answer, type the correct code in the answer area.

Answer:

Explanation:
CREATE FUNCTION SalesDB.fn_ABC ( @ProductID int )
RETURNS TABLE
AS
RETURN
(
SELECT OrderID, ProductID, ShipDate, OrderDate, Amount

FROM Sales. ProductsSalesV
WHERE ProductID = @ProductID
ORDER BY OrderDate DESC
);