NEW QUESTION NO: 20
DRAG DROP
You need to create a stored procedure that meets the following requirements:
Produces a warning if the credit limit parameter is greater than 7,000

Propagates all unexpected errors to the calling process

How should you complete the Transact-SQL statement? To answer, drag the appropriate Transact-SQP segments to the correct locations. Each Transact-SQL segments may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.
Select and Place:

Answer:

Explanation/Reference:
Explanation:
Box 1: THROW 51000, 'Warning: Credit limit isover 7,000!",1
THROW raises an exception and transfers execution to a CATCH block of a TRY...CATCH construct in SQL Server.
THROW syntax:
THROW [ { error_number | @local_variable },
{ message | @local_variable },
{ state | @local_variable } ]
[; ]
Box2: RAISERROR (@ErrorMessage, 16,1)
RAISERROR generates an error message and initiates error processing for the session. RAISERROR can either reference a user-defined message stored in the sys.messages catalog view or build a message dynamically. The message is returned as a server error message to the calling application or to an associated CATCH block of a TRY...CATCH construct. New applications should use THROW instead.
Severity levels from 0 through 18 can be specified by any user. Severity levels from 19through 25 can only be specified by members of the sysadmin fixed server role or users with ALTER TRACE permissions. For severity levels from 19 through 25, the WITH LOG option is required.
On Severity level 16. Using THROW to raise an exception
The following example shows how to use the THROW statement to raise an exception.
Transact-SQL
THROW 51000, 'The record does not exist.', 1;
Here is the result set.
Msg 51000, Level 16, State 1, Line 1
The record does not exist.
Note: RAISERROR syntax:
RAISERROR( { msg_id | msg_str | @local_variable }
{ ,severity ,state }
[,argument [ ,...n ] ] )
[WITH option [ ,...n ] ]
Note: The ERROR_MESSAGE function returns the message text of the error that caused the CATCH block of a TRY...CATCH construct to be run.
References:
https://msdn.microsoft.com/en-us/library/ms178592.aspx
https://msdn.microsoft.com/en-us/library/ms190358.aspx
https://msdn.microsoft.com/en-us/library/ee677615.aspx
NEW QUESTION NO: 21
DRAG DROP
You have a table named HR.Employees as shown in the exhibit. (Click the exhibit button.)

You need to write a query that will change the value of the job title column to Customer Representative for any employee who lives in Seattle and has a job title of Sales Representative. If the employee does not have a manager defined, you must not change the title.
Which three Transact-SQL segments should you use to develop the solution? To answer, move the appropriate Transact-SQL segments from the list of Transact-SQL segments to the answer area and arrange them in the correct order.
Select and Place:

Answer:

Explanation/Reference:
Explanation:
References: https://msdn.microsoft.com/en-us/library/ms177523.aspx
NEW QUESTION NO: 22
SIMULATION
You have a database that contains the following tables.

You need to create a query that lists the lowest-performing salespersons based on the current year-to-date sales period. The query must meet the following requirements:
Return a column named Fullname that includes the salesperson FirstName, a space, and then

LastName.
Include the current year-to-date sales for each salesperson.

Display only data for the three salespersons with the lowest year-to-year sales values.

Exclude salespersons that have no value for TerritoryID.

Construct the query using the following guidelines:
Use the first letter of a table name as the table alias.

Use two-part column names.

Do not surround object names with square brackets.

Do not use implicit joins.

Use only single quotes for literal text.

Use aliases only if required.


Part of the correct Transact-SQL has been provided in the answer area below. Enter the code in the answer area that resolves the problem and meets the stated goals or requirements. You can add code within the code that has been provided as well as below it.

Use the Check Syntax button to verify your work. Any syntax or spelling errors will be reported by line and character position.
Answer:
See the solution below
Explanation/Reference:
SELECT TOP(3) FirstName + ' ' + LastName AS Fullname, S.SalesYTD
FROM Person as P INNER JOIN SalesPerson AS S
ON P.PersonID = S.SalesPersonID
WHERE S.TerritoryID IS NOT NULL
ORDER BY S.SalesYTD
Explanation;
On ordering: ASC | DESC
Specifies that the values in the specified column should be sorted in ascending or descending order. ASC sorts from the lowest value to highest value. DESC sorts from highest value to lowest value. ASC is the default sort order. Null values are treated as the lowest possible values.
References: https://msdn.microsoft.com/en-us/library/ms189463.aspx
NEW QUESTION NO: 23
HOTSPOT
Note: This question is part of a series of questions that use the same scenario. For your convenience, the scenario is repeated in each question. Each question presents a different goal and answer choices, but the text of the scenario is exactly the same in each question in this series.
Start of repeated scenario
You have a database that contains the tables shown in the exhibit. (Click the Exhibit button.)

You review the Employee table and make the following observations:
Every record has a value in the ManagerID except for the Chief Executive Officer (CEO).

The FirstName and MiddleName columns contain null values for some records.

The valid values for the Title column are Sales Representative manager, and CEO.

You review the SalesSummary table and make the following observations:
The ProductCode column contains two parts: The first five digits represent a product code, and the last

seven digits represent the unit price. The unit price uses the following pattern: ####.##.
You observe that for many records, the unit price portion of the ProductCode column contains values.

The RegionCode column contains NULL for some records.

Sales data is only recorded for sales representatives.

You are developing a series of reports and procedures to support the business. Details for each report or procedure follow.
Sales Summary report: This report aggregates data by year and quarter. The report must resemble the following table.

Sales Manager report: This report lists each sales manager and the total sales amount for all employees that report to the sales manager.
Sales by Region report: This report lists the total sales amount by employee and by region. The report must include the following columns: EmployeeCode, MiddleName, LastName, RegionCode, and SalesAmount. If MiddleName is NULL, FirstName must be displayed. If both FirstName and MiddleName have null values, the world Unknown must be displayed/ If RegionCode is NULL, the word Unknown must be displayed.
Report1: This report joins data from SalesSummary with the Employee table and other tables. You plan to create an object to support Report1. The object has the following requirements:
be joinable with the SELECT statement that supplies data for the report

can be used multiple times with the SELECT statement for the report

be usable only with the SELECT statement for the report

not be saved as a permanent object

Report2: This report joins data from SalesSummary with the Employee table and other tables.
You plan to create an object to support Report1. The object has the following requirements:
be joinable with the SELECT statement that supplies data for the report

can be used multiple times for this report and other reports

accept parameters

be saved as a permanent object

Sales Hierarchy report: This report aggregates rows, creates subtotal rows, and super-aggregates rows over the SalesAmount column in a single result-set. The report uses SaleYear, SaleQuarter, and SaleMonth as a hierarchy. The result set must not contain a grand total or cross-tabulation aggregate rows.
Current Price Stored Procedure: This stored procedure must return the unit price for a product when a product code is supplied. The unit price must include a dollar sign at the beginning. In addition, the unit price must contain a comma every three digits to the left of the decimal point, and must display two digits to the left of the decimal point. The stored procedure must not throw errors, even if the product code contains invalid data.
End of Repeated Scenario
You need to create the query for the Sales by Region report.
Which function should you apply to each column? To answer, select the appropriate options in the answer area.
Hot Area:

Answer:

Explanation/Reference:
Explanation:
Box 1: COALESCE
COALESCE evaluates the arguments in order and returns the current value of the first expression that initially does not evaluate to NULL.
If MiddleName is NULL, FirstName must be displayed. If both FirstName and MiddleName have null values, the world Unknown must be displayed.
The following example shows how COALESCE selects the data from the first column that has a nonnull value.
SELECT Name, Class, Color, ProductNumber,
COALESCE(Class, Color, ProductNumber) AS FirstNotNull
FROM Production.Product;
Not NULLIF: NULLIF returns the first expression if the two expressions are not equal. If the expressions are equal, NULLIF returns a null value of the type of the first expression.
Box 2: COALESCE
If RegionCodeis NULL, the word Unknown must be displayed.
References:https://docs.microsoft.com/en-us/sql/t-sql/language-elements/coalesce-transact-sql
NEW QUESTION NO: 24
Note: This question is part of a series of questions that use the same or similar answer choices. An answer choice may be correct for more than one question in the series. Each question is independent of the other questions in this series. Information and details provided in a question apply only to that question.
You create a table by running the following Transact-SQL statement:

You are developing a report that aggregates customer data only for the year 2014. The report requires that the data be denormalized.
You need to return the data for the report.
Which Transact-SQL statement should you run?
A:

B:

C:

D:

E:

F:

G:

H:

A. Option A
B. Option D
C. Option H
D. Option F
E. Option E
F. Option B
G. Option G
H. Option C
Answer: G
NEW QUESTION NO: 25
DRAG DROP
Note: This question is part of a series of questions that use the same scenario. For your convenience, the scenario is repeated in each question. Each question presents a different goal and answer choices, but the text of the scenario is exactly the same in each question on this series.
You have a database that tracks orders and deliveries for customers in North America. System versioning is enabled for all tables. The database contains the Sales.Customers, Application.Cities, and Sales.CustomerCategories tables.
Details for the Sales.Customers table are shown in the following table:

Details for the Application.Cities table are shown in the following table:

Details for the Sales.CustomerCategories table are shown in the following table:

You are creating a report to show when the first customer account was opened in each city. The report contains a line chart with the following characteristics:
The chart contains a data point for each city, with lines connecting the points.

The X axis contains the position that the city occupies relative to other cities.

The Y axis contains the date that the first account in any city was opened.

An example chart is shown below for five cities:

During a sales promotion, customers from various cities open new accounts on the same date.
You need to write a query that returns the data for the chart.
How should you complete the Transact-SQL statement? To answer, drag the appropriate Transact-SQL segments to the correct locations. Each Transact-SQL segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.
NOTE: Each correct selection is worth one point.
Select and Place:

Answer:

Explanation/Reference:
Explanation:
Box 1: RANK() OVER
RANK returns the rank of each row within the partition of a result set. The rank of a row is one plus thenumber of ranks that come before the row in question.
ROW_NUMBER and RANK are similar. ROW_NUMBER numbers all rows sequentially (for example 1, 2,
3, 4, 5).
Incorrect Answers:
DENSE_RANK returns the rank of rows within the partition of a result set, without any gaps in the ranking.
The rank of a row is one plus the number of distinct ranks that come before the row in question.
Box 2: (PARTITION BY CityID ORDER BY MIN(AccountOpenedDate) DESC)
Syntax for RANK: RANK ( ) OVER ( [ partition_by_clause ] order_by_clause ) Box 3: GROUP BY CityID References: https://msdn.microsoft.com/en-us/library/ms176102.aspx