- (Exam Topic 2)
A table named Profits stores the total profit made each year within a territory. The Profits table has columns named Territory, Year, and Profit.
You need to create a report that displays the profits made by each territory for each year and its previous year. Which Transact-SQL query should you use?
Correct Answer:
C
LAG accesses data from a previous row in the same result set without the use of a self-join in SQL Server 2016. LAG provides access to a row at a given physical offset that comes before the current row. Usethis analytic function in a SELECT statement to compare values in the current row with values in a previous row.
Use ORDER BY Year, not ORDER BY Territory.
Example: The following example uses the LAG function to return the difference in sales quotas fora specific employee over previous years. Notice that because there is no lag value available for the first row, the default of zero (0) is returned.
USE AdventureWorks2012; GO
SELECT BusinessEntityID, YEAR(QuotaDate) AS SalesYear, SalesQuota AS CurrentQuota, LAG(SalesQuota, 1,0) OVER (ORDER BY YEAR(QuotaDate)) AS PreviousQuota
FROM Sales.SalesPersonQuotaHistory
WHERE BusinessEntityID = 275 and YEAR(QuotaDate) IN (\'2005\',\'2006\');
- (Exam Topic 1)
You are developing a database application by using Microsoft SQL Server 2012. An application that uses a database begins to run slowly.
You discover that during reads, the transaction experiences blocking from concurrent updates. You need to ensure that throughout the transaction the data maintains the original version. What should you do?
Correct Answer:
M
- (Exam Topic 1)
You administer a Microsoft SQL Server 2012 database named ContosoDb. Tables are defined as shown in the exhibit. (Click the Exhibit button.)
< ><>>< ><>
Correct Answer:
G
- (Exam Topic 1)
You have a view that was created by using the following code:
< ><>>< > >< > >>< >
Solution:
CREATE FUNCTION Sales.fn_OrdersByTerritory (@T int) RETURNS TABLE
AS RETURN ( SELECT
OrderID, OrderDate, SalesTerritoryID, TotalDue
FROM Sales.OrdersByTerritory WHERE SalesTerritoryID=@T
)
Does this meet the goal?
Correct Answer:
A
- (Exam Topic 1)
You have an XML schema collection named Sales.InvoiceSchema.
You need to declare a variable of the XML type named invoice. The solution must ensure that the invoice is validated by using Sales.InvoiceSchema.
The solution must ensure that the invoice variable is validated by using Sales.InvoiceSchema schema. Provide the correct code in the answer area.
Solution:
DECLARE @invoice XML(Sales.InvoiceSchema)
Does this meet the goal?
Correct Answer:
A