PrepAway - Latest Free Exam Questions & Answers

You generate a daily report ac…

You generate a daily report according to the following query:



You need to improve the performance of the query.

What should you do?

A. Drop the UDF and rewrite the report query as follows:

SELECT c.CustomerName

FROM Sales.Customer c

INNER JOIN Sales.Customer s ON c.CustomerID = c.CustomerID

GROUP BY c.CustomerID

HAVING MAX(s.OrderDate) < DATEADD(DAY, -90, GETDATE())

B. Drop the UDF and rewrite the report query as follows:

SELECT c.CustomerName

FROM Sales.Customer c

WHERE NOT EXISTS (

SELECT s.OrderDate

FROM Sales.SalesOrders

WHERE s.OrderDate > DATEADD(DAY, -90, GETDATE())

AND s.CustomerID = c.CustomerID)

C. Drop the UDF and rewrite the report query as follows:

SELECT DISTINCT c.CustomerName

FROM Sales.Customer c

INNER JOIN Sales.SalesOrder s ON c.CustomerID = s.CustomerID

WHERE s.OrderDate < DATEADD(DAY, -90, GETDATE())

D. Rewrite the report query as follows:

SELECT c.CustomerName

FROM Sales.Customer c

WHERE NOT EXISTS (

SELECT OrderDate

FROM Sales.ufnGetRecentOrders(c.CustomerID, 90))

Rewrite the UDF as follows:

CREATE FUNCTION Sales.ufnGetRecentOrders(@CustomerID int, @MaxAge datetime)

RETURNS @OrderTable TABLE (OrderDate datetime) TABLE
AS
BEGIN
INSET @OrderTable
SELECT OrderDate
FROM Sales.SalesOrder s
WHERE s.CustomerID = @CustomerID
AND s.OrderDate > DATEADD(DAY, -@MaxAge, GETDATE())
RETURN
END

Explanation:


Leave a Reply