PrepAway - Latest Free Exam Questions & Answers

Solution: You run the following Transact-SQL statement:…

Note: This question is part of a series of questions that present the same scenario. Each question in
the series contains a unique solution that might meet the stated goals. Some question sets might have
more than one correct solution, while others might not have a correct solution.
After you answer a question in this section. You will NOT be able to return to it. As a result, these
questions will not appear in the review screen.
You have a database that tracks orders and deliveries for customers in North America. The database contains
the following tables:
Sales.Customers

Application.Cities

Sales.CustomerCategories

The company’s development team is designing a customer directory application. The application must list
customers by the area code of their phone number. The area code is defined as the first three characters of the
phone number.
The main page of the application will be based on an indexed view that contains the area and phone number
for all customers.
You need to return the area code from the PhoneNumber field.
Solution: You run the following Transact-SQL statement:

Does the solution meet the goal?

PrepAway - Latest Free Exam Questions & Answers

A.
Yes

B.
No

Explanation:
We need SELECT TOP 1 @areacode =.. to ensure that only one value is returned.

4 Comments on “Solution: You run the following Transact-SQL statement:…

  1. eder says:

    the correct answer is NO.

    remember,The area code is defined as the first three characters of the
    phone number.
    como bien dice los 3 primeros caracteres se usa left

    CREATE FUNCTION dbo.areaCode(
    @phoneNumber NVARCHAR(50)
    )
    RETURNS NVARCHAR(MAX)
    WITH SCHEMABINDING
    AS
    BEGIN
    DECLARE @areaCode NVARCHAR(MAX)
    SELECT @areaCode=LEFT(@phoneNumber,3)
    RETURN @areaCode
    END




    6



    2
    1. ashleyliang says:

      Agree.
      The STRING_SPLIT(@phonenumber, ‘-‘) returns a value set for each phonenumber rather than only the area code.

      For example,

      SELECT value from STRING_SPLIT(‘425-555-0187’, ‘-‘) returns:

      425
      555
      0187

      The function then will not get the area code to return.




      1



      1

Leave a Reply